From a80fcab038903818ec52053ee32b9ad8dfc7ad99 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 10 Nov 2026 08:32:26 -0500 Subject: [PATCH] .NET: Fix flaky MultiStepOperationTimeout unit test Wait for the timeout token to be cancelled instead of a fixed delay, which could finish before the timer callback on loaded runners. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 85e502db-0565-4d9c-94bb-b86f57fc296c --- .../Harness/MultiStepOperationTimeoutTests.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/MultiStepOperationTimeoutTests.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/MultiStepOperationTimeoutTests.cs index cc1c30a7143..12c20a2bbe0 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/MultiStepOperationTimeoutTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/MultiStepOperationTimeoutTests.cs @@ -16,9 +16,14 @@ public async Task RunStep_CompletedStepDoesNotResetTimeoutAsync() // Act int firstResult = timeout.RunStep(_ => 1); - await Task.Delay(200); + + // Wait for the timer callback itself; a fixed delay can finish first on a loaded runner. + var expired = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + using CancellationTokenRegistration registration = timeout.Token.Register(() => expired.TrySetResult(true)); + Task completed = await Task.WhenAny(expired.Task, Task.Delay(TimeSpan.FromSeconds(30))); // Assert + Assert.Same(expired.Task, completed); Assert.Equal(1, firstResult); Assert.Throws(() => timeout.RunStep(_ => 2)); }