Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/2] support/testing: remove hardcoded sleep from python-django test
@ 2024-02-16 13:18 Marcus Hoffmann via buildroot
  2024-02-16 13:18 ` [Buildroot] [PATCH 2/2] package/python-whitenoise: new package Marcus Hoffmann via buildroot
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Marcus Hoffmann via buildroot @ 2024-02-16 13:18 UTC (permalink / raw)
  To: buildroot

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 <buildroot@bubu1.eu>
---
 .../tests/package/test_python_django.py        | 18 ++++++++++++------
 1 file changed, 12 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..0973467a2a 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,17 @@ 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
+        else:
+            self.assertTrue(False, "Timeout while waiting for django server")
 
 
 class TestPythonPy3Django(TestPythonDjango):
-- 
2.34.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-02-05 10:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-16 13:18 [Buildroot] [PATCH 1/2] support/testing: remove hardcoded sleep from python-django test Marcus Hoffmann via buildroot
2024-02-16 13:18 ` [Buildroot] [PATCH 2/2] package/python-whitenoise: new package Marcus Hoffmann via buildroot
2024-08-05 10:02   ` Thomas Petazzoni via buildroot
2024-08-07 10:25     ` Marcus Hoffmann via buildroot
2025-02-05 10:41   ` Thomas Petazzoni via buildroot
2025-02-05 10:41   ` Thomas Petazzoni via buildroot
2024-02-16 13:23 ` [Buildroot] [PATCH 1/2] support/testing: remove hardcoded sleep from python-django test Marcus Hoffmann via buildroot
2024-02-16 19:55   ` Arnout Vandecappelle via buildroot
2024-02-20 16:46 ` Yann E. MORIN

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox