test_python_waitress.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import time
  2. from tests.package.test_python import TestPythonPackageBase
  3. class TestPythonWaitress(TestPythonPackageBase):
  4. __test__ = True
  5. config = TestPythonPackageBase.config + \
  6. """
  7. BR2_PACKAGE_PYTHON3=y
  8. BR2_PACKAGE_PYTHON_FLASK=y
  9. BR2_PACKAGE_PYTHON_WAITRESS=y
  10. """
  11. sample_scripts = ["tests/package/sample_python_flask.py"]
  12. def test_run(self):
  13. self.login()
  14. self.check_sample_scripts_exist()
  15. cmd = self.interpreter + " -m waitress sample_python_flask:app > /dev/null 2>&1 &"
  16. # give some time to setup the server
  17. _, exit = self.emulator.run(cmd, timeout=self.timeout)
  18. # Give enough time for the uvicorn server to start up
  19. for attempt in range(30):
  20. time.sleep(1)
  21. cmd = "wget -q -O - http://127.0.0.1:8080/"
  22. output, exit_code = self.emulator.run(cmd, timeout=self.timeout)
  23. if exit_code == 0:
  24. self.assertEqual(output[0], 'Hello, World!')
  25. break
  26. else:
  27. self.assertTrue(False, "Timeout while waiting for waitress server")