Skip to content

Commit

Permalink
pyportaltest: Allow registering a session close callback
Browse files Browse the repository at this point in the history
This works around a race condition where test_close_session_signal
registers a callback but on slow systems the Close signal may be sent
before said callback can be registered.

Note that we need to keep the returned SessionResult alive so the
XdpSession isn't cleaned up by the Python GC before we finish the test.

Closes #166
  • Loading branch information
whot authored and GeorgesStavracas committed Oct 23, 2024
1 parent 0f8f627 commit a885ffe
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tests/pyportaltest/test_remotedesktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def create_session(
start_session=True,
persist_mode=None,
restore_token=None,
cb_closed_signal=None,
) -> SessionSetup:
params = params or {}
# To make the tests easier, load ScreenCast automatically if we have
Expand Down Expand Up @@ -120,6 +121,9 @@ def create_session_done(portal, task, data):

assert session.get_session_type() == Xdp.SessionType.REMOTE_DESKTOP

if cb_closed_signal:
session.connect("closed", cb_closed_signal)

if outputs:
# open the PW remote by default since we need it anyway for Start()
handle = session.open_pipewire_remote()
Expand Down Expand Up @@ -581,9 +585,6 @@ def test_close_session_signal(self):
Ensure that we get the GObject signal when our session is closed
externally.
"""
params = {"close-after-start": 500}
setup = self.create_session(params=params)
session = setup.session

session_closed_signal_received = False

Expand All @@ -592,8 +593,10 @@ def session_closed(session):
session_closed_signal_received = True
self.mainloop.quit()

session.connect("closed", session_closed)

params = {"close-after-start": 500}
_ = self.create_session(
params=params, cb_closed_signal=session_closed
) # keep SessionResult alive
self.mainloop.run()

assert session_closed_signal_received is True

0 comments on commit a885ffe

Please sign in to comment.