[Buildroot] [git commit] support/testing: remove hardcoded sleep from python-flask test
Thomas Petazzoni
thomas.petazzoni at bootlin.com
Sun Feb 11 22:12:03 UTC 2024
commit: https://git.buildroot.net/buildroot/commit/?id=cbe0f4de67aef0f4695073c2047ba65cc420c83a
branch: https://git.buildroot.net/buildroot/commit/?id=refs/heads/master
Similar to the new fastapi test, instead of waiting for a hard coded
amount of time we can retry every second until the server is available
and abort if after the timeout we still didn't manage to connect.
Signed-off-by: Marcus Hoffmann <buildroot at bubu1.eu>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
---
support/testing/tests/package/test_python_flask.py | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/support/testing/tests/package/test_python_flask.py b/support/testing/tests/package/test_python_flask.py
index 9d8587e918..32d9da34a5 100644
--- a/support/testing/tests/package/test_python_flask.py
+++ b/support/testing/tests/package/test_python_flask.py
@@ -21,9 +21,13 @@ class TestPythonPy3Flask(TestPythonPackageBase):
_, exit_code = self.emulator.run(cmd, timeout=self.timeout)
# Give enough time for the flask server to start up
- time.sleep(30)
+ for attempt in range(30):
+ time.sleep(1)
- cmd = "wget -q -O - http://127.0.0.1:5000/"
- output, exit_code = self.emulator.run(cmd, timeout=self.timeout)
- self.assertEqual(exit_code, 0)
- self.assertEqual(output[0], "Hello, World!")
+ cmd = "wget -q -O - http://127.0.0.1:5000/"
+ output, exit_code = self.emulator.run(cmd, timeout=self.timeout)
+ if exit_code == 0:
+ self.assertEqual(output[0], 'Hello, World!')
+ break
+ else:
+ self.assertTrue(False, "Timeout while waiting for flask server")
More information about the buildroot
mailing list