Skip to content

Commit 14cbe65

Browse files
committed
tests: don't use sleep(1) to enforce message ordering
Replace a call to sleep(1) with a check that the data from the wait-for-session script is sent before the read call.
1 parent 241b88f commit 14cbe65

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

qrexec/tests/socket/agent.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ def test_wait_for_session(self):
353353
"""\
354354
#!/bin/sh
355355
cat {}
356-
sleep 0.1
357356
read input
358357
echo "arg: $1, remote domain: $QREXEC_REMOTE_DOMAIN, input: $input"
359358
""".format(
@@ -371,20 +370,22 @@ def test_wait_for_session(self):
371370
user = getpass.getuser()
372371

373372
target = self.execute_qubesrpc("qubes.Service+arg", "domX")
373+
self.assertEqual(target.recv_message(), (
374+
qrexec.MSG_DATA_STDOUT,
375+
(
376+
b"wait for session: arg: , remote domain: domX, user: "
377+
+ user.encode("ascii", "strict")
378+
+ b"\n"
379+
),
380+
))
374381
target.send_message(qrexec.MSG_DATA_STDIN, b"stdin data\n")
375-
target.send_message(qrexec.MSG_DATA_STDIN, b"")
382+
# Do not send EOF. Shell read doesn't need it, and this checks that
383+
# qrexec does not wait for EOF on stdin before sending the exit code
384+
# from the remote process.
376385
messages = target.recv_all_messages()
377386
self.assertListEqual(
378387
util.sort_messages(messages),
379388
[
380-
(
381-
qrexec.MSG_DATA_STDOUT,
382-
(
383-
b"wait for session: arg: , remote domain: domX, user: "
384-
+ user.encode()
385-
+ b"\n"
386-
),
387-
),
388389
(
389390
qrexec.MSG_DATA_STDOUT,
390391
b"arg: arg, remote domain: domX, input: stdin data\n",

0 commit comments

Comments
 (0)