Skip to content

CSHARP-5823: Investigate and fix flaky PrunePoolAsync_should_remove_all_expired_connections test#1844

Merged
sanych-sun merged 4 commits intomongodb:mainfrom
sanych-sun:csharp5823
Jan 12, 2026
Merged

CSHARP-5823: Investigate and fix flaky PrunePoolAsync_should_remove_all_expired_connections test#1844
sanych-sun merged 4 commits intomongodb:mainfrom
sanych-sun:csharp5823

Conversation

@sanych-sun
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings January 10, 2026 01:05
@sanych-sun sanych-sun requested a review from a team as a code owner January 10, 2026 01:05
@sanych-sun sanych-sun added the chore Non–user-facing code changes (tests, build scripts, etc.). label Jan 10, 2026
@sanych-sun sanych-sun requested review from BorisDog and ajcvickers and removed request for ajcvickers January 10, 2026 01:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 fixes a flaky test by restructuring how expired connections are identified and validated during connection pool pruning. The test previously had a race condition where connections were marked as expired after creation, making timing unpredictable.

Changes:

  • Refactored the test to mark connections as expired during initialization rather than after pool setup
  • Modified the event validation logic to focus on removal events that occurred during the actual prune operation
  • Adjusted timing and synchronization mechanisms to eliminate race conditions

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

connectionsExpired.Add(connectionId);
connectionMock
.SetupSequence(c => c.IsExpired)
.Returns(() => isInitializationDone); // Once we mark test as initialized chosen connection could be expired
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

Corrected spelling of 'withing' to 'within' in the comment.

Copilot uses AI. Check for mistakes.
_capturedEvents.WaitForOrThrowIfTimeout(events => events.Count(e => e is ConnectionPoolRemovedConnectionEvent) >= connectionsExpired.Count, TimeSpan.FromSeconds(10));
var poolPruneEvents = _capturedEvents.Events
.SkipWhile(e => e is not ConnectionPoolRemovingConnectionEvent)
// it is expected that all connections should be expired and removed withing the single maintenance run
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

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

Corrected spelling of 'withing' to 'within'.

Suggested change
// it is expected that all connections should be expired and removed withing the single maintenance run
// it is expected that all connections should be expired and removed within the single maintenance run

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

LGTM!

@sanych-sun sanych-sun merged commit b81b853 into mongodb:main Jan 12, 2026
31 of 36 checks passed
@sanych-sun sanych-sun deleted the csharp5823 branch January 12, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Non–user-facing code changes (tests, build scripts, etc.).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants