-
Notifications
You must be signed in to change notification settings - Fork 0
fix (tests): Collections were still being modified when asserting #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Collections were still being modified by background tasks(s) when test assertions were enumerating the collection, causing trouble. A total of four tests were fixed. Fixes #3
There was a problem hiding this 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 reorders test cleanup and assertion logic to prevent potential race conditions when accessing shared collections. The cleanup steps (cancellation and waiting for event tasks to complete) are now performed before assertions, ensuring thread-safe access to event collections without requiring locks during assertions.
- Moved cleanup code (cancellation and awaiting event tasks) before assertion sections in four test methods
- Updated comments to clarify that assertions are now safe to perform without locks after event tasks complete
- Ensures event collection access is synchronized by completing background tasks before reading collection state
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…fied Even after awaiting eventTask the collection could still be modified, correcting this by taking a thread-safe snapshot of the collection before making assertions Fixes #3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Apply thread-safe snapshot pattern to all tests that access the shared events collection to prevent "Collection was modified; enumeration operation may not execute" errors in Github Actions. Changes: - Take array snapshot of events collection while holding lock before making assertions in 6 tests: Where_ShouldFilterEvents, Take_ShouldLimitNumberOfEvents, Skip_ShouldSkipEvents, DistinctUntilChanged_ShouldFilterConsecutiveDuplicates, Throttle_ShouldLimitEventRate, and Debounce_ShouldDelayEvents - Reorder cleanup and assertions to ensure background tasks complete before accessing the collection - Use .Length property instead of .Count for array assertions - Add explanatory comments for exception handling during cleanup This ensures complete thread-safety by creating immutable snapshots of the collection while holding the lock, eliminating any possibility of race conditions during enumeration. All 16 tests now pass reliably in both local and GitHub Actions environments. Fixes #3
Collections were still being modified by background tasks(s) when test assertions were enumerating the collection, causing trouble. A total of four tests were fixed.
Fixes #3