Skip to content

Commit b67e3e5

Browse files
Copilotstephentoub
andauthored
Replace Task.WhenAny + Task.Delay timeout pattern with .WaitAsync(TimeSpan) (#805)
* Initial plan * Replace Task.WhenAny+Task.Delay with .WaitAsync(TimeSpan) Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent e1ea008 commit b67e3e5

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

dotnet/test/MultiClientTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,9 @@ public async Task Both_Clients_See_Tool_Request_And_Completion_Events()
134134
Assert.Contains("MAGIC_hello_42", response!.Data.Content ?? string.Empty);
135135

136136
// Wait for all broadcast events to arrive on both clients
137-
var timeout = Task.Delay(TimeSpan.FromSeconds(10));
138-
var allEvents = Task.WhenAll(
137+
await Task.WhenAll(
139138
client1Requested.Task, client2Requested.Task,
140-
client1Completed.Task, client2Completed.Task);
141-
Assert.Equal(allEvents, await Task.WhenAny(allEvents, timeout));
139+
client1Completed.Task, client2Completed.Task).WaitAsync(TimeSpan.FromSeconds(10));
142140

143141
await session2.DisposeAsync();
144142

dotnet/test/SessionTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ public async Task Should_Receive_Session_Events()
272272
await session.SendAsync(new MessageOptions { Prompt = "What is 100+200?" });
273273

274274
// Wait for session to become idle (indicating message processing is complete)
275-
var completed = await Task.WhenAny(idleReceived.Task, Task.Delay(TimeSpan.FromSeconds(60)));
276-
Assert.Equal(idleReceived.Task, completed);
275+
await idleReceived.Task.WaitAsync(TimeSpan.FromSeconds(60));
277276

278277
// Should have received multiple events (user message, assistant message, idle, etc.)
279278
Assert.NotEmpty(receivedEvents);

0 commit comments

Comments
 (0)