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
@@ -284,15 +288,21 @@ def _run_server() -> None:
284288 thread .start ()
285289
286290 try :
287- while not server .started :
288- if server_caught_exception .wait (1e-3 ):
291+ start_time = time .time ()
292+ while True :
293+ if server .started :
294+ break
295+ if server_caught_exception .wait (1e-3 ): # pragma: nocover
289296 raise RuntimeError (
290297 f"Server failed to start: { server_exception !r} " ,
291298 ) from server_exception
299+ if time .time () - start_time > timeout : # pragma: nocover
300+ raise TimeoutError ("Server did not start in time" )
301+ time .sleep (1e-3 )
292302 yield server
293303 finally :
294304 server .should_exit = True
295- thread .join ()
305+ thread .join (timeout = timeout )
296306
297307
298308@pytest .fixture (scope = "session" )
You can’t perform that action at this time.
0 commit comments