From 07a444d08804b3a453e4d01686ba0bef990070ca Mon Sep 17 00:00:00 2001 From: Julien Olivain Date: Tue, 26 Nov 2024 19:28:55 +0100 Subject: [PATCH] support/testing: improve mosquitto test reliability The mosquitto runtime test can randomly fail on slow runners, see [1]. This commit improves this test in the following ways: - the mosquitto_sub subscriber process is now started in a subshell to suppress the job control messages (to prevent any spurious messages when the job stops), - the standard error is redirected to /dev/null, to prevent the printing of any messages, - the mosquitto_pub publisher process is started later, by increasing the sleep time, - finally, a new sleep time is introduced between the mosquitto_pub publisher process and the check of the mosquitto_sub subscriber, to make sure it will have time to write its output and exit. Fixes: [1] [1] https://gitlab.com/buildroot.org/buildroot/-/jobs/8453386454 Signed-off-by: Julien Olivain Signed-off-by: Thomas Petazzoni --- support/testing/tests/package/test_mosquitto.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/support/testing/tests/package/test_mosquitto.py b/support/testing/tests/package/test_mosquitto.py index ba10b30b00b5..6b256e5e27f0 100644 --- a/support/testing/tests/package/test_mosquitto.py +++ b/support/testing/tests/package/test_mosquitto.py @@ -25,13 +25,19 @@ def test_run(self): msg = "Hello Buildroot!" # We subscribe to a topic and write one message to a log file. - self.assertRunOk(f"mosquitto_sub -t {topic} -C 1 > {log} &") + cmd = f"( mosquitto_sub -t {topic} -C 1 > {log} 2> /dev/null & )" + self.assertRunOk(cmd) - time.sleep(1) + # We give some time to the subscriber process to settle. + time.sleep(5) # We publish a message. self.assertRunOk(f"mosquitto_pub -t {topic} -m '{msg}'") + # We give some more time to the subscriber process to write + # the log and quit. + time.sleep(5) + # We check the log file contains our message. out, ret = self.emulator.run(f"cat {log}") self.assertEqual(ret, 0)