From c4ea0cb036ad7bc428e523637c0a7133cbcab015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 4 Nov 2026 00:14:40 -0300 Subject: [PATCH] Run the slow last read tests on a fake clock (Refs #1006) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- .../LocatorWaitFor/ASlowLastReadTests.cs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/E2E.Tests/LocatorWaitFor/ASlowLastReadTests.cs b/tests/E2E.Tests/LocatorWaitFor/ASlowLastReadTests.cs index f8b86f973..53ffc86c1 100644 --- a/tests/E2E.Tests/LocatorWaitFor/ASlowLastReadTests.cs +++ b/tests/E2E.Tests/LocatorWaitFor/ASlowLastReadTests.cs @@ -2,7 +2,6 @@ // Modified by Dario Kondratiuk. // SPDX-License-Identifier: Apache-2.0 -using System.Diagnostics; using E2E.Engine; using E2E.Tests.LocatorEngine; @@ -16,10 +15,12 @@ public sealed class ASlowLastReadTests { private static readonly SemanticNode Banner = new() { Ref = "banner", Role = "alert", Name = "Saved", TestId = "banner" }; - /// A screen whose every read takes 350 ms, bounded by its operation's budget, and whose banner shows up at 1050 ms. - private static Locator SlowScreen() + /// + /// A screen whose every read takes 350 ms, bounded by its operation's budget, and whose banner shows up at 1050 ms. The reads move a + /// fake clock, so a loaded runner cannot shift the banner past the last read. + /// + private static Locator SlowScreen(SteppingTime clock) { - var clock = Stopwatch.StartNew(); var screen = new Screen( _ => Task.FromResult(new Observation { Route = "/", Roots = [] }), (_, _, _) => Task.CompletedTask, @@ -27,11 +28,12 @@ private static Locator SlowScreen() () => { }, TimeSpan.FromMilliseconds(1_000), TimeSpan.FromMilliseconds(1_000), + clock: clock, locate: async (_, budget, _) => { // The banner is read when the read ends, as a device answers with the screen of its end. - await SlowLocate.AnswerAsync(TimeSpan.FromMilliseconds(350), [], budget).ConfigureAwait(false); - return clock.ElapsedMilliseconds >= 1_050 ? [Banner] : []; + await SlowLocate.AnswerAsync(clock, TimeSpan.FromMilliseconds(350), [], budget).ConfigureAwait(false); + return clock.Elapsed >= TimeSpan.FromMilliseconds(1_050) ? [Banner] : []; }); return screen.GetByTestId("banner"); } @@ -39,12 +41,14 @@ private static Locator SlowScreen() [Fact] public async Task Still_finishes_past_the_deadline_so_waitFor_sees_a_node_that_showed_up_during_it() { - await SlowScreen().WaitForAsync(); + var clock = new SteppingTime(); + await clock.RunAsync(SlowScreen(clock).WaitForAsync()); } [Fact] public async Task Still_finishes_past_the_deadline_so_an_assertion_sees_a_node_that_showed_up_during_it() { - await Expect.That(SlowScreen()).ToBeVisibleAsync(); + var clock = new SteppingTime(); + await clock.RunAsync(Expect.That(SlowScreen(clock)).ToBeVisibleAsync()); } }