CSHARP-5823: Investigate and fix flaky PrunePoolAsync_should_remove_all_expired_connections test#1844
Merged
sanych-sun merged 4 commits intomongodb:mainfrom Jan 12, 2026
Merged
Conversation
…ll_expired_connections test
Contributor
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Corrected spelling of 'withing' to 'within' in the comment.
| _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 |
There was a problem hiding this comment.
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 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.