From 3fbc00a42d0d246bad5b5381194c5c4775764cf7 Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Thu, 11 Dec 2025 13:43:41 +0200 Subject: [PATCH] [Test] Add hacks for backwards-compatibility --- test/functional/util/dummy_http.py | 6 +++++- test/functional/util/dummy_http_early_response.py | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/test/functional/util/dummy_http.py b/test/functional/util/dummy_http.py index b82e58167a..c1dd97a28e 100755 --- a/test/functional/util/dummy_http.py +++ b/test/functional/util/dummy_http.py @@ -151,7 +151,11 @@ async def main(): if __name__ == "__main__": try: - asyncio.run(main()) + if hasattr(asyncio, 'run') and callable(getattr(asyncio, 'run')): + asyncio.run(main()) + else: + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) except Exception as e: print(f"dummy_http.py: FATAL ERROR: {type(e).__name__}: {e}", file=sys.stderr) traceback.print_exc(file=sys.stderr) diff --git a/test/functional/util/dummy_http_early_response.py b/test/functional/util/dummy_http_early_response.py index 2fbb2942cc..bacfb18d18 100755 --- a/test/functional/util/dummy_http_early_response.py +++ b/test/functional/util/dummy_http_early_response.py @@ -265,8 +265,13 @@ class EarlyResponseServer: async def serve_forever(self): """Serve until cancelled.""" - async with self.server: - await self.server.serve_forever() + # Python 3.7+ has serve_forever(), but 3.6 doesn't + if hasattr(self.server, 'serve_forever'): + async with self.server: + await self.server.serve_forever() + else: + # For Python 3.6 compatibility, use async context manager + await asyncio.Event().wait() async def main(): @@ -290,7 +295,11 @@ async def main(): if __name__ == "__main__": try: - asyncio.run(main()) + if hasattr(asyncio, 'run') and callable(getattr(asyncio, 'run')): + asyncio.run(main()) + else: + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) except KeyboardInterrupt: print("Shutting down...", file=sys.stderr) except Exception as e: -- 2.47.3