Skip to content

Commit 95f3349

Browse files
committed
Fix TeamChatSenderTests to ensure event subscription occurs before message publication
1 parent 8d8b656 commit 95f3349

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

tests/RustPlusBot.Features.Connections.Tests/TeamChatSenderTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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
{

0 commit comments

Comments
 (0)