Skip to content

Conversation

@steingran
Copy link
Owner

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

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
@steingran steingran requested a review from Copilot November 3, 2025 21:36
Copy link
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 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
@steingran steingran requested a review from Copilot November 3, 2025 22:14
Copy link
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

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
@steingran steingran merged commit 8964fd0 into main Nov 4, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Collection was modified; enumeration operation may not execute"

2 participants