Skip to content

Commit ee8f58c

Browse files
JusterZhuclaude
andcommitted
fix(test): opt all EventManager tests into NonParallel collection to prevent thread-safety race
EventManager.Reset() creates a fresh Lazy<EventManager> backing the singleton, but the switch is not atomic across threads. Under xUnit's default parallel class execution, one test can call Reset() between another test's EventManager.Instance invocations, causing listeners to be registered on one instance and dispatched on another — producing empty callback assertions. Fixes flaky failures observed on Ubuntu CI runners in CoreTest where the test output is nondeterministic due to OS-level scheduling differences. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2aa4279 commit ee8f58c

5 files changed

Lines changed: 5 additions & 0 deletions

File tree

tests/CoreTest/Bootstrap/ParameterMatrixAndEventTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace CoreTest.Bootstrap
2222
/// - Various encoding/format combinations
2323
/// - UpdateRequest validation edge cases
2424
/// </summary>
25+
[Collection("NonParallel_EventManager")]
2526
public class ParameterMatrixAndEventTests : IDisposable
2627
{
2728
private readonly string _testDir;

tests/CoreTest/Event/EventListenerBatchTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace CoreTest.Event;
99
/// Batch tests for <see cref="IUpdateEventListener"/> and <see cref="EventManager"/>
1010
/// following AAAT (Arrange-Act-Assert-TearDown).
1111
/// </summary>
12+
[Collection("NonParallel_EventManager")]
1213
public class EventListenerBatchTests : IDisposable
1314
{
1415
/// <summary>TearDown: clear singleton state after each test for isolation.</summary>

tests/CoreTest/Event/EventListenerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace CoreTest.Event;
88

9+
[Collection("NonParallel_EventManager")]
910
public class EventListenerTests : IDisposable
1011
{
1112
/// <summary>TearDown: clear singleton state after each test for isolation.</summary>

tests/CoreTest/Event/EventManagerConcurrencyTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace CoreTest.Event;
88

9+
[Collection("NonParallel_EventManager")]
910
public class EventManagerConcurrencyTests : IDisposable
1011
{
1112
/// <summary>TearDown: clear singleton state after each test for isolation.</summary>

tests/CoreTest/Event/EventManagerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace CoreTest.Event;
77
/// Implements <see cref="IDisposable"/> for explicit TearDown — clears singleton state
88
/// after each test to ensure test isolation regardless of test execution order.
99
/// </summary>
10+
[Collection("NonParallel_EventManager")]
1011
public class EventManagerTests : IDisposable
1112
{
1213
public class TestEventArgs : EventArgs

0 commit comments

Comments
 (0)