File tree Expand file tree Collapse file tree
tests/RustPlusBot.Features.Connections.Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -250,9 +250,16 @@ public async Task StatusEvents_CarryWasConnected_OnlyAfterAConnectedDrop()
250250
251251 using var cts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 30 ) ) ;
252252 var events = new List < ConnectionStatusChangedEvent > ( ) ;
253+ // Register the subscription synchronously on this thread BEFORE any connection work runs.
254+ // InMemoryEventBus registers the channel eagerly when SubscribeAsync is invoked, so buffering
255+ // starts here. Deferring the call into the Task.Run below would race the supervisor's first
256+ // publishes: on a slow runner the initial Connecting/Connected events are dropped, the drop
257+ // event (WasConnected=true) becomes the collector's first observation, and the "before first
258+ // Connected" assertion fails.
259+ var stream = h . Bus . SubscribeAsync < ConnectionStatusChangedEvent > ( cts . Token ) ;
253260 _ = Task . Run ( async ( ) =>
254261 {
255- await foreach ( var e in h . Bus . SubscribeAsync < ConnectionStatusChangedEvent > ( cts . Token ) )
262+ await foreach ( var e in stream )
256263 {
257264 lock ( events )
258265 {
You can’t perform that action at this time.
0 commit comments