kumquat-buildroot/support/testing/tests/package/test_python_flask.py
Marcus Hoffmann cbe0f4de67 support/testing: remove hardcoded sleep from python-flask test
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@bubu1.eu>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2024-02-11 23:12:03 +01:00

34 lines
1.1 KiB
Python

from tests.package.test_python import TestPythonPackageBase
import os
import time
class TestPythonPy3Flask(TestPythonPackageBase):
__test__ = True
config = TestPythonPackageBase.config + \
"""
BR2_PACKAGE_PYTHON3=y
BR2_PACKAGE_PYTHON_FLASK=y
"""
sample_scripts = ["tests/package/sample_python_flask.py"]
timeout = 60
def test_run(self):
self.login()
self.check_sample_scripts_exist()
cmd = "FLASK_APP=%s %s -m flask run > /dev/null 2>&1 &" % (os.path.basename(self.sample_scripts[0]),
self.interpreter)
_, exit_code = self.emulator.run(cmd, timeout=self.timeout)
# Give enough time for the flask server to start up
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)
if exit_code == 0:
self.assertEqual(output[0], 'Hello, World!')
break
else:
self.assertTrue(False, "Timeout while waiting for flask server")