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.

Closes #166
  • Loading branch information
whot committed Oct 9, 2024
1 parent 7c3e462 commit c98b91b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tests/pyportaltest/test_remotedesktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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 @@ -119,6 +120,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 @@ -580,9 +584,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 @@ -591,8 +592,8 @@ 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)
self.setup_mainloop_with_timeout(timeout_ms=0).run()

assert session_closed_signal_received is True

0 comments on commit c98b91b

Please sign in to comment.