Skip to content

test(django): Remove forking in ASGI tests#6410

Merged
sl0thentr0py merged 1 commit into
masterfrom
neel/forked/asgi
May 26, 2026
Merged

test(django): Remove forking in ASGI tests#6410
sl0thentr0py merged 1 commit into
masterfrom
neel/forked/asgi

Conversation

@sl0thentr0py
Copy link
Copy Markdown
Member

@sl0thentr0py sl0thentr0py commented May 26, 2026

Drop @pytest.mark.forked from the Django ASGI test suite and stop mutating the module-level asgi_application instance. On Python 3.12 in GitHub Actions' multi-threaded runner, pytest-forked forks a multi-threaded process; the asyncio event loop in the child inherits dead threads and silently hangs, consuming the full CI budget.

Removed @pytest.mark.forked

Removed from all 10 affected tests. The sentry_init fixture already handles SDK state save/restore correctly without forking.

Fresh ASGI app per test

Three tests called asgi_application.load_middleware(is_async=True), which mutates the shared module-level instance and leaks state into subsequent tests. They now use a new make_asgi_application fixture that returns get_asgi_application — letting tests build a fresh app after sentry_init, so middleware instrumentation is installed before Django builds the chain.

Concurrent execution tests

Replaced the deprecated asyncio.get_event_loop() + create_task pattern with asyncio.gather().

Issues

@sl0thentr0py sl0thentr0py changed the title test(django): Fix ASGI test hangs on Python 3.12 CI test(django): Remove forked ASGI tests May 26, 2026
@sl0thentr0py sl0thentr0py changed the title test(django): Remove forked ASGI tests test(django): Remove forking in ASGI tests May 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 26, 2026

Codecov Results 📊

79 passed | Total: 79 | Pass Rate: 100% | Execution Time: 909ms

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 16035 uncovered lines.


Generated by Codecov Action

- op="middleware.django": description="django.middleware.csrf.CsrfViewMiddleware.process_view"
- op="view.render": description="simple_async_view"
- op="event.django": description="django.db.close_old_connections"
- op="event.django": description="django.core.cache.close_caches"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ordering of these is now non-deterministic so I'm simply removing checking them now, not what this test is about and they're tested elsewhere

@sl0thentr0py sl0thentr0py marked this pull request as ready for review May 26, 2026 13:22
@sl0thentr0py sl0thentr0py requested a review from a team as a code owner May 26, 2026 13:22
@sl0thentr0py
Copy link
Copy Markdown
Member Author

agents failure unrelated

The ASGI test suite uses @pytest.mark.forked + @pytest.mark.asyncio.
On Python 3.12 in GitHub Actions' multi-threaded runner, pytest-forked
forks a multi-threaded process; the asyncio event loop in the child
inherits dead threads, causing silent hangs that consume the full
CI budget.

Drop @pytest.mark.forked from all 10 affected tests — the sentry_init
fixture already handles SDK state save/restore correctly without forking.

Three of those tests called asgi_application.load_middleware(is_async=True),
which mutates the shared module-level asgi_application instance and leaks
state into subsequent tests. Introduce a make_asgi_application fixture
that returns get_asgi_application so tests can build a fresh app after
sentry_init (ensuring middleware instrumentation is installed before
Django builds the chain).

Also replace the deprecated asyncio.get_event_loop() pattern in the
concurrent execution tests with asyncio.gather().

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sl0thentr0py sl0thentr0py enabled auto-merge (squash) May 26, 2026 13:57
@sl0thentr0py sl0thentr0py merged commit 21e636c into master May 26, 2026
157 checks passed
@sl0thentr0py sl0thentr0py deleted the neel/forked/asgi branch May 26, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants