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)); }