From dc3f1faa8b8339a72da45efeeb3085045002ca28 Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Fri, 16 Feb 2024 14:18:13 +0100 Subject: [PATCH] support/testing: remove hardcoded sleep from python-django test Instead of waiting for a hardcoded time of 30s we check periodically every second if the server is already up. If it isn't up after the full timeout (which is the same as before) expired the test fails. We need to redirect all output of the background started task to /dev/null now as it otherwise confuses the emulator.run() exit code parsing logic (as it gets out of order messages from the emulator). Signed-off-by: Marcus Hoffmann yann.morin.1998@free.fr: simplify assert test] Signed-off-by: Yann E. MORIN --- .../testing/tests/package/test_python_django.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/support/testing/tests/package/test_python_django.py b/support/testing/tests/package/test_python_django.py index e1ca50f6d8..29e8ee0b2e 100644 --- a/support/testing/tests/package/test_python_django.py +++ b/support/testing/tests/package/test_python_django.py @@ -1,3 +1,5 @@ +import time + from tests.package.test_python import TestPythonPackageBase @@ -16,13 +18,16 @@ class TestPythonDjango(TestPythonPackageBase): self.assertIn("Operations to perform:", output[0]) self.assertEqual(exit_code, 0) - cmd = "cd /opt/testsite && " + self.interpreter + " ./manage.py runserver 0.0.0.0:1234 & " - # give some time to setup the server - cmd += "sleep {}".format(str(30 * self.emulator.timeout_multiplier)) + cmd = "cd /opt/testsite && " + self.interpreter + " ./manage.py runserver 0.0.0.0:1234 > /dev/null 2>&1 & " self.assertRunOk(cmd, timeout=timeout) - - cmd = "netstat -ltn 2>/dev/null | grep 0.0.0.0:1234" - self.assertRunOk(cmd) + # give some time to setup the server + for attempt in range(30 * self.emulator.timeout_multiplier): + time.sleep(1) + cmd = "netstat -ltn 2>/dev/null | grep 0.0.0.0:1234" + _, exit_code = self.emulator.run(cmd) + if exit_code == 0: + break + self.assertEqual(exit_code, 0, "Timeout while waiting for django server") class TestPythonPy3Django(TestPythonDjango):