From 16d693ed1dcc04985e77d1c5b041c5c996ffbdcb Mon Sep 17 00:00:00 2001 From: Dario Kondratiuk Date: Tue, 10 Nov 2026 14:12:21 -0300 Subject: [PATCH 1/2] Run the hung-resolve contract test on a fake clock (Refs #1006) Co-Authored-By: Claude Haiku 5.5 --- .../LocatorEngineResolveRetryContractTests.cs | 13 +++++++++---- tests/E2E.Tests/LocatorEngine/SlowLocate.cs | 7 +++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/E2E.Tests/LocatorEngine/LocatorEngineResolveRetryContractTests.cs b/tests/E2E.Tests/LocatorEngine/LocatorEngineResolveRetryContractTests.cs index ed25bfd89..5c845df29 100644 --- a/tests/E2E.Tests/LocatorEngine/LocatorEngineResolveRetryContractTests.cs +++ b/tests/E2E.Tests/LocatorEngine/LocatorEngineResolveRetryContractTests.cs @@ -81,16 +81,21 @@ private static Screen LocatingScreen(List { calls++; return SlowLocate.AnswerAsync(TimeSpan.FromMilliseconds(100), [], budget); }, - budget => { calls++; return SlowLocate.HangAsync(budget); }, + budget => { calls++; return SlowLocate.AnswerAsync(clock, TimeSpan.FromMilliseconds(100), [], budget); }, + budget => { calls++; return SlowLocate.HangAsync(clock, budget); }, ], - []); + [], + clock: clock); var deadline = new Deadline(TimeSpan.FromMilliseconds(2_000), screen.Clock); - var error = await Assert.ThrowsAsync(() => screen.GetByRole("button").ResolveExactlyOneAsync(deadline, CancellationToken.None)); + var resolving = screen.GetByRole("button").ResolveExactlyOneAsync(deadline, CancellationToken.None); + await clock.RunAsync(resolving.ContinueWith(_ => { }, TaskScheduler.Default)); + var error = await Assert.ThrowsAsync(() => resolving); Assert.Equal("ACTION_FAILED", error.Code); Assert.Equal(2, calls); diff --git a/tests/E2E.Tests/LocatorEngine/SlowLocate.cs b/tests/E2E.Tests/LocatorEngine/SlowLocate.cs index ca19a27ee..8bf0703b8 100644 --- a/tests/E2E.Tests/LocatorEngine/SlowLocate.cs +++ b/tests/E2E.Tests/LocatorEngine/SlowLocate.cs @@ -44,6 +44,13 @@ public static Task> AnswerAsync(FakeTimeProvider clo return Task.FromResult(nodes); } + /// A locate that never answers on its own, on a fake clock: it takes the whole and ends with OPERATION_TIMEOUT. + public static Task> HangAsync(FakeTimeProvider clock, TimeSpan budget) + { + clock.Advance(budget); + return Task.FromException>(new EngineException(EngineErrorCodes.OperationTimeout, "operation timed out", retryable: false)); + } + /// A locate that never answers on its own, ended at . public static async Task> HangAsync(TimeSpan budget) { From cb4ae49aa9ff0dbabd74029ead633102753d7a57 Mon Sep 17 00:00:00 2001 From: Dario Kondratiuk Date: Tue, 10 Nov 2026 14:39:33 -0300 Subject: [PATCH 2/2] Keep the LocatorEngine retry wait on the injected clock and bound the fake-clock pump (Refs #1006) Co-Authored-By: Claude Haiku 5.5 --- src/E2E/Locator/LocatorEngine.cs | 2 +- tests/E2E.Tests/SteppingTime.cs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/E2E/Locator/LocatorEngine.cs b/src/E2E/Locator/LocatorEngine.cs index 2f02d0223..048d98f0f 100644 --- a/src/E2E/Locator/LocatorEngine.cs +++ b/src/E2E/Locator/LocatorEngine.cs @@ -423,7 +423,7 @@ internal async Task ResolveExactlyOneAsync(LocatorExpression expre throw await NotFoundAsync(expression, Clock.GetElapsedTime(started), token).ConfigureAwait(false); } - await Task.Delay(PollInterval, token).ConfigureAwait(false); + await Task.Delay(PollInterval, Clock, token).ConfigureAwait(false); } } diff --git a/tests/E2E.Tests/SteppingTime.cs b/tests/E2E.Tests/SteppingTime.cs index 1dde9b4b7..03aef6c52 100644 --- a/tests/E2E.Tests/SteppingTime.cs +++ b/tests/E2E.Tests/SteppingTime.cs @@ -2,6 +2,7 @@ // Modified by Dario Kondratiuk. // SPDX-License-Identifier: Apache-2.0 +using System.Diagnostics; using Microsoft.Extensions.Time.Testing; namespace E2E.Tests; @@ -33,6 +34,8 @@ public override ITimer CreateTimer(TimerCallback callback, object? state, TimeSp /// Runs the clock until ends, then returns its outcome. public async Task RunAsync(Task pending) { + // A poll that waits on a real timer, not this clock, would never let the clock move: fail instead of spinning forever. + var idle = Stopwatch.StartNew(); while (!pending.IsCompleted) { // Let the poll finish what it is doing, such as a read that completes and drops its own timeout. @@ -44,8 +47,13 @@ public async Task RunAsync(Task pending) if (!pending.IsCompleted && NextDue() is { } due) { + idle.Restart(); Advance(due > GetUtcNow() ? due - GetUtcNow() : TimeSpan.Zero); } + else if (!pending.IsCompleted && idle.Elapsed > TimeSpan.FromSeconds(30)) + { + throw new TimeoutException("The poll waits on no timer of the fake clock for 30 seconds; it must wait on this clock."); + } } await pending;