This PR moves the creation of the asyncio.Event from RebuildServer.__init__ to the Starlette lifespan to ensure it's created within the event loop context. This resolves the error we were seeing due to the event loop not being available during initialization.
Added a rebuild test
Executes the lifespan by opening TestClient in a context manager.
Modify test rst file and receives "refresh" from WebSocket.
[!WARNING]
Tests fail erratically.
There's a high probability that executing lifespan in the test code is causing pytest command to randomly fail after successful test runs. Please retry the CI. It's truly random: FATAL: exception not rethrown. I suspect this is due to the interaction between Starlette's TestClient, anyio threads, or related dependencies, but haven't found a solution yet.
Fixes #178
Move
asyncio.Event
creation to lifespanThis PR moves the creation of the
asyncio.Event
fromRebuildServer.__init__
to the Starlette lifespan to ensure it's created within the event loop context. This resolves the error we were seeing due to the event loop not being available during initialization.Added a rebuild test
There's a high probability that executing lifespan in the test code is causing
pytest
command to randomly fail after successful test runs. Please retry the CI. It's truly random:FATAL: exception not rethrown
. I suspect this is due to the interaction between Starlette's TestClient, anyio threads, or related dependencies, but haven't found a solution yet.While I'm satisfied with the test code itself, should I consider removing the test? Manual testing has been successful.