-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to django-asgi-lifecycle instead of custom asgi lifecycle impl…
…ementation
- Loading branch information
1 parent
eb407f5
commit e4dc958
Showing
9 changed files
with
587 additions
and
640 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,30 @@ | ||
import pytest | ||
from asgiref.sync import async_to_sync | ||
|
||
from conf.asgi import APPLICATION_LIFECYCLE | ||
from conf.asgi import application | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def call_application_shutdown(): | ||
def ensure_asgi_lifecycle(): | ||
""" | ||
Call application shutdown during test session teardown. | ||
Call application shutdown lifecycle event. | ||
This cannot be an async fixture because the scope is session | ||
and pytest-asynio's `event_loop` fixture, which is auto-used | ||
for async tests and fixtures, is function scoped, which is | ||
incomatible with session scoped fixtures. `async_to_sync` works | ||
fine here, so it's not a problem. | ||
This cannot yet call the startup signal due to: | ||
https://github.com/illagrenan/django-asgi-lifespan/pull/80 | ||
""" | ||
scope = {"type": "lifespan"} | ||
|
||
async def noop(*args, **kwargs): | ||
... | ||
|
||
async def shutdown(): | ||
return {"type": "lifespan.shutdown"} | ||
|
||
yield | ||
async_to_sync(APPLICATION_LIFECYCLE.shutdown)() | ||
async_to_sync(application)(scope, shutdown, noop) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters