diff --git a/lib/galaxy_test/driver/driver_util.py b/lib/galaxy_test/driver/driver_util.py index bf72edd0cc99..2dd2890b0b34 100644 --- a/lib/galaxy_test/driver/driver_util.py +++ b/lib/galaxy_test/driver/driver_util.py @@ -583,7 +583,7 @@ def run_in_loop(loop): t = threading.Thread(target=run_in_loop, args=(loop,)) t.start() - return server, port + return server, port, t def cleanup_directory(tempdir): @@ -725,10 +725,11 @@ def stop(self): class EmbeddedServerWrapper(ServerWrapper): - def __init__(self, app, server, name, host, port): + def __init__(self, app, server, name, host, port, thread=None): super().__init__(name, host, port) self._app = app self._server = server + self._thread = thread @property def app(self): @@ -745,6 +746,11 @@ def stop(self): self._server.should_exit = True log.info(f"Embedded web server {self.name} stopped") + if self._thread is not None: + log.info("Stopping embedded server thread") + self._thread.join() + log.info("Embedded server thread stopped") + if self._app is not None: log.info(f"Stopping application {self.name}") self._app.shutdown() @@ -873,11 +879,11 @@ def launch_uvicorn(webapp_factory, prefix=DEFAULT_CONFIG_PREFIX, galaxy_config=N ) from galaxy.webapps.galaxy.fast_app import initialize_fast_app app = initialize_fast_app(gx_wsgi_webapp, gx_app) - server, port = uvicorn_serve(app, host=host, port=port) + server, port, thread = uvicorn_serve(app, host=host, port=port) set_and_wait_for_http_target(prefix, host, port) log.info(f"Embedded uvicorn web server for {name} started at {host}:{port}") return EmbeddedServerWrapper( - gx_app, server, name, host, port + gx_app, server, name, host, port, thread=thread )