From dfd804f1227be23404a80de3ac8fdde9a363d6dc Mon Sep 17 00:00:00 2001 From: Demi Marie Obenour Date: Sat, 13 Apr 2024 15:24:16 -0400 Subject: [PATCH] Fix flaky qrexec agent tests Various tests assumed that qrexec would deliver stdout in a single message. Qrexec does not make this guarantee: calls to write(2), send(2), sendmsg(2), etc are not guaranteed to correspond 1-to-1 to MSG_DATA_STDOUT messages on the vchan. This caused https://gitlab.com/QubesOS/qubes-core-qrexec/-/jobs/6616564043 to wrongly fail, even thouggh the code is correct. Fix this problem by concatenating the payloads of all stdout messages into a single bytes object before comparing with the expected stdout value. Also add a utility function for this, saving a lot of code in tests. --- qrexec/tests/socket/agent.py | 158 +++++++---------------------------- 1 file changed, 29 insertions(+), 129 deletions(-) diff --git a/qrexec/tests/socket/agent.py b/qrexec/tests/socket/agent.py index 94dfb133..9c56dfe6 100644 --- a/qrexec/tests/socket/agent.py +++ b/qrexec/tests/socket/agent.py @@ -56,6 +56,21 @@ def check_dom0(self, dom0): ), ) + def assertExpectedStdout(self, target, expected_stdout: bytes, *, exit_code=0): + messages = util.sort_messages(target.recv_all_messages()) + self.assertListEqual(messages[-3:], + [ + (qrexec.MSG_DATA_STDOUT, b""), + (qrexec.MSG_DATA_STDERR, b""), + (qrexec.MSG_DATA_EXIT_CODE, struct.pack("