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 @@ -98,9 +98,15 @@ public async Task Inbound_line_publishes_event_with_active_player_flag()
9898 using var cts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 30 ) ) ;
9999 var received =
100100 new TaskCompletionSource < TeamMessageReceivedEvent > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
101+
102+ // Subscribe on the calling thread so the bus eagerly registers the channel BEFORE the message
103+ // is raised. Doing this inside Task.Run would race the single RaiseTeamMessage below: if the
104+ // publish wins, the one event is dropped and received.Task never completes (a 30s timeout that
105+ // surfaces only under CI scheduling pressure). Only the iteration runs in the background.
106+ var stream = bus . SubscribeAsync < TeamMessageReceivedEvent > ( cts . Token ) ;
101107 var subscription = Task . Run ( async ( ) =>
102108 {
103- await foreach ( var e in bus . SubscribeAsync < TeamMessageReceivedEvent > ( cts . Token ) )
109+ await foreach ( var e in stream )
104110 {
105111 if ( received . TrySetResult ( e ) )
106112 {
You can’t perform that action at this time.
0 commit comments