local_social_test_support.py (693B)
1 """Scoped HTTP server ownership for the real local-social fixture tests.""" 2 3 from contextlib import contextmanager 4 from threading import Thread 5 6 from scripts.fixture_connections import OwnedHTTPServer 7 8 9 @contextmanager 10 def blossom_server(handler, state): 11 handler.state = state 12 server = OwnedHTTPServer(("127.0.0.1", 0), handler) 13 state.blossom_port = server.server_address[1] 14 thread = Thread(target=server.serve_forever, daemon=True) 15 thread.start() 16 try: 17 yield 18 finally: 19 server.shutdown() 20 server.server_close() 21 thread.join(timeout=5) 22 if thread.is_alive(): 23 raise RuntimeError("fixture server teardown is incomplete")