Skip to content

Fix flaky Mocha Postgres tests with shared Npgsql helper#9981

Merged
glen-84 merged 2 commits into
mainfrom
gai/mocha-test-npgsql-warning-helper
Jun 24, 2026
Merged

Fix flaky Mocha Postgres tests with shared Npgsql helper#9981
glen-84 merged 2 commits into
mainfrom
gai/mocha-test-npgsql-warning-helper

Conversation

@glen-84

@glen-84 glen-84 commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

  • Each test in the Mocha Postgres test project builds its own service provider, so EF accumulates more than twenty internal service providers across a run and throws ManyServiceProvidersCreatedWarning when a context is created past that threshold. Because it depends on test ordering and parallelism, the failure surfaced intermittently in CI (the *ServiceRegistration tests).
  • Add a UseTestNpgsql options-builder helper that applies the Npgsql provider and ignores that warning, and route every context-building call site through it. This replaces the inline ignores that previously covered only some call sites.

Test plan

  • Ran the test assembly with --parallel none, which forces the sequential ordering that exposes the flake: the affected tests fail before the change and pass after.

Copilot AI review requested due to automatic review settings June 24, 2026 13:16

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.

Pull request overview

This PR addresses intermittent CI failures in Mocha.EntityFrameworkCore.Postgres.Tests caused by EF Core’s ManyServiceProvidersCreatedWarning being triggered (and treated as an error) when many test-created service providers accumulate during a run. It centralizes the Npgsql + warning configuration into a single helper and routes all DbContext option construction through it to eliminate ordering/parallelism-dependent flakes.

Changes:

  • Added UseTestNpgsql extension methods to consistently configure the Npgsql provider and ignore CoreEventId.ManyServiceProvidersCreatedWarning.
  • Updated all Postgres test call sites to use UseTestNpgsql instead of inline UseNpgsql(...) / ConfigureWarnings(...).
  • Removed now-unneeded EF diagnostics using directives and duplicated inline warning suppression.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/SchedulingServiceRegistrationTests.cs Switches test DbContext registration to the shared UseTestNpgsql helper.
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/SagaStateEntityConfigurationTests.cs Uses UseTestNpgsql for model-building context options.
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/SagaServiceRegistrationTests.cs Routes both direct options creation and DI registration through UseTestNpgsql.
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/PostgresSchedulingIntegrationTests.cs Replaces duplicated inline warning suppression with UseTestNpgsql.
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/PostgresSagaStoreTests.cs Uses UseTestNpgsql for DbContext creation in saga store setup.
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/PostgresOutboxIntegrationTests.cs Consolidates DbContext configuration via UseTestNpgsql.
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/PostgresMessageOutboxTests.cs Updates all DbContextOptionsBuilder usage to UseTestNpgsql.
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/PostgresMessageInboxTests.cs Updates DbContext options creation to use UseTestNpgsql.
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/OutboxServiceRegistrationTests.cs Uses UseTestNpgsql and removes inline warning suppression.
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/OutboxEntityConfigurationTests.cs Uses UseTestNpgsql for design-time model creation.
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/InboxServiceRegistrationTests.cs Switches DbContext registration to UseTestNpgsql.
src/Mocha/test/Mocha.EntityFrameworkCore.Postgres.Tests/Helpers/TestDbContextOptionsBuilderExtensions.cs Introduces the shared UseTestNpgsql helper (generic + non-generic overloads) and central warning suppression.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@glen-84 glen-84 merged commit 0712479 into main Jun 24, 2026
141 checks passed
@glen-84 glen-84 deleted the gai/mocha-test-npgsql-warning-helper branch June 24, 2026 15:33
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