Skip to content

Fix test servers staying alive until their test class ends - #10482

Merged
glen-84 merged 1 commit into
mainfrom
gai/dispose-test-servers-per-test
Oct 5, 2026
Merged

glen-84 merged 1 commit into
mainfrom
gai/dispose-test-servers-per-test

Conversation

@glen-84

@glen-84 glen-84 commented Oct 5, 2026

Copy link
Copy Markdown
Member

Summary

  • TestServerFactory is a class fixture that kept every TestServer it created until the test class finished. GraphQLOverHttpSpecTests alone creates about 315 servers, each building seven schemas at startup, so the HotChocolate.AspNetCore.Tests process grows to about 16 GB, the full memory of a GitHub-hosted runner.
  • On CI this shows up as process-wide pauses of 6 to 14 seconds in every run, and occasionally much longer. Timing-sensitive tests fail when a pause lands on them: GraphQLOverWebSocket.WebSocketProtocolTests.Send_Subscribe_SyntaxError took 42.8 seconds against its 15-second budget in this run, and the GraphQLOverHttpSpecTests.EventStream_* keep-alive failures run 3 to 13 seconds over their usual 30.
  • ServerTestBase now disposes and releases the servers a test created when that test finishes, through a new TestServerFactory.DisposeServers(). Constructors are unchanged. The Opa AuthorizationTests overrides the new DisposeAsync, since xUnit calls only DisposeAsync on a test class that has one.

Test plan

  • HotChocolate.AspNetCore.Tests on net11.0 with --coverage, pinned to 4 cores and capped at 12 GB of memory: before the change the test host threw OutOfMemoryException after 563 of 819 tests, after it all 819 complete with a peak resident memory of 509 MB (15.9 GB uncapped before the change).
  • Built every test project that uses ServerTestBase with code style enforced, and ran their tests on net11.0: AspNetCore.Authorization, Transport.Sockets.Client, Transport.Http, Diagnostics, Utilities.Introspection, Data.Sorting.InMemory, and the StrawberryShake transport and code generation tests pass.
  • AspNetCore.Authorization.Opa.Tests starts OPA in a container and is covered by CI.

Copilot AI lite review requested due to automatic review settings October 5, 2026 09:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified that would block approval.

Review effort: Lite
Findings: None

What changed in this PR

Fixes test-server memory retention by disposing servers after each test instead of at class teardown.

Changes:

  • Adds DisposeServers() and clears tracked instances.
  • Makes ServerTestBase dispose servers asynchronously per test.
  • Updates OPA teardown to invoke base cleanup.
File Description
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests.Utilities/​TestServerFactory.cs Updated as part of this pull request.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Tests.Utilities/​ServerTestBase.cs Updated as part of this pull request.
src/​HotChocolate/​AspNetCore/​test/​AspNetCore.Authorization.Opa.Tests/​AuthorizationTests.cs Updated as part of this pull request.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@glen-84
glen-84 merged commit 6b18c9f into main Oct 5, 2026
159 checks passed
@glen-84
glen-84 deleted the gai/dispose-test-servers-per-test branch October 5, 2026 09:47
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