File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -268,7 +268,11 @@ async def watch_restarts(self) -> None: # pragma: no cover
268268 await self .startup ()
269269
270270
271- def serve_in_thread (server : TestServer ) -> typing .Iterator [TestServer ]:
271+ def serve_in_thread (
272+ server : TestServer ,
273+ * ,
274+ timeout : float = 10.0 ,
275+ ) -> typing .Iterator [TestServer ]:
272276 server_exception = None
273277 server_caught_exception = threading .Event ()
274278
@@ -286,15 +290,21 @@ def _run_server() -> None:
286290 thread .start ()
287291
288292 try :
289- while not server .started :
290- if server_caught_exception .wait (1e-3 ):
293+ start_time = time .time ()
294+ while True :
295+ if server .started :
296+ break
297+ if server_caught_exception .wait (1e-3 ): # pragma: nocover
291298 raise RuntimeError (
292299 f"Server failed to start: { server_exception !r} " ,
293300 ) from server_exception
301+ if time .time () - start_time > timeout : # pragma: nocover
302+ raise TimeoutError ("Server did not start in time" )
303+ time .sleep (1e-3 )
294304 yield server
295305 finally :
296306 server .should_exit = True
297- thread .join ()
307+ thread .join (timeout = timeout )
298308
299309
300310@pytest .fixture (scope = "session" )
You can’t perform that action at this time.
0 commit comments