From f7a26a7c2af8010a92ebd2dbe3e5cae9f6df4fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Thu, 5 Nov 2026 17:05:35 -0300 Subject: [PATCH 1/3] Run the mobile shared-budget observe test on a clock the test moves Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- .../E2E.Mobile.Tests/Engine/ObservationTests.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/E2E.Mobile.Tests/Engine/ObservationTests.cs b/tests/E2E.Mobile.Tests/Engine/ObservationTests.cs index 659ce22ab..2613b70fd 100644 --- a/tests/E2E.Mobile.Tests/Engine/ObservationTests.cs +++ b/tests/E2E.Mobile.Tests/Engine/ObservationTests.cs @@ -658,21 +658,28 @@ public async Task Rethrows_OPERATION_TIMEOUT_from_capturePixels_during_observe() public async Task Shares_one_budget_across_observe_steps_so_screenshot_cannot_take_a_fresh_budget() { var h = Harness.Create(); + h.Clock.ManualTimers = true; var session = await OpenAttempt(h); - // The snapshot carries its geometry, so the only screenshot is the observation's pixels. - h.Fake.RespondAsync(DeviceMethods.CaptureSnapshot, async (_, _) => + // The snapshot carries its geometry, so the only screenshot is the observation's pixels. The snapshot takes 150 ms of the test's + // clock, so a loaded runner cannot make it use up the 500 ms budget before the screenshot starts. + h.Fake.RespondAsync(DeviceMethods.CaptureSnapshot, (_, _) => { - await Task.Delay(150); - return WithViewport(402, 874); + h.Clock.Spend(TimeSpan.FromMilliseconds(150)); + return Task.FromResult(WithViewport(402, 874)); }); var screenshots = 0; + var shot = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); h.Fake.RespondAsync(DeviceMethods.CaptureScreenshot, (_, _) => { Interlocked.Increment(ref screenshots); + shot.TrySetResult(); return Never(); }); var started = DateTimeOffset.UtcNow; - var failure = await Assert.ThrowsAsync(() => session.ObserveAsync(new ObserveOptions { Pixels = true }, TimeSpan.FromMilliseconds(500), CancellationToken.None)); + var observing = Assert.ThrowsAsync(() => session.ObserveAsync(new ObserveOptions { Pixels = true }, TimeSpan.FromMilliseconds(500), CancellationToken.None)); + await shot.Task; + await h.Clock.SpendUntil(observing, TimeSpan.FromMilliseconds(400)); + var failure = await observing; Assert.Equal("OPERATION_TIMEOUT", failure.Code); Assert.Equal(1, screenshots); Assert.True(DateTimeOffset.UtcNow - started < TimeSpan.FromSeconds(3)); From 0fcff9fc75c4adff91dfe621640cbb7d8705e054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Thu, 5 Nov 2026 17:07:58 -0300 Subject: [PATCH 2/3] Check the shared budget on the test's clock, not the wall clock Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- tests/E2E.Mobile.Tests/Engine/ObservationTests.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/E2E.Mobile.Tests/Engine/ObservationTests.cs b/tests/E2E.Mobile.Tests/Engine/ObservationTests.cs index 2613b70fd..8866b5a75 100644 --- a/tests/E2E.Mobile.Tests/Engine/ObservationTests.cs +++ b/tests/E2E.Mobile.Tests/Engine/ObservationTests.cs @@ -675,13 +675,14 @@ public async Task Shares_one_budget_across_observe_steps_so_screenshot_cannot_ta shot.TrySetResult(); return Never(); }); - var started = DateTimeOffset.UtcNow; + var started = h.Clock.GetUtcNow(); var observing = Assert.ThrowsAsync(() => session.ObserveAsync(new ObserveOptions { Pixels = true }, TimeSpan.FromMilliseconds(500), CancellationToken.None)); await shot.Task; - await h.Clock.SpendUntil(observing, TimeSpan.FromMilliseconds(400)); + await h.Clock.SpendUntil(observing, TimeSpan.FromMilliseconds(350)); var failure = await observing; Assert.Equal("OPERATION_TIMEOUT", failure.Code); Assert.Equal(1, screenshots); - Assert.True(DateTimeOffset.UtcNow - started < TimeSpan.FromSeconds(3)); + // The snapshot spent 150 ms and the step 350: the screenshot ended at the 500 ms of the one budget, not 500 ms after its own start. + Assert.Equal(TimeSpan.FromMilliseconds(500), h.Clock.GetUtcNow() - started); } } From b1a563ad41715412b6b8f3761ce0986e2ed5b6ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Thu, 5 Nov 2026 17:26:15 -0300 Subject: [PATCH 3/3] Assert only the exact lower bound of the shared budget on the test's clock Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Ls2e1yaZFgZ3FEJkYScfkK --- tests/E2E.Mobile.Tests/Engine/ObservationTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/E2E.Mobile.Tests/Engine/ObservationTests.cs b/tests/E2E.Mobile.Tests/Engine/ObservationTests.cs index 8866b5a75..8d154cb41 100644 --- a/tests/E2E.Mobile.Tests/Engine/ObservationTests.cs +++ b/tests/E2E.Mobile.Tests/Engine/ObservationTests.cs @@ -682,7 +682,7 @@ public async Task Shares_one_budget_across_observe_steps_so_screenshot_cannot_ta var failure = await observing; Assert.Equal("OPERATION_TIMEOUT", failure.Code); Assert.Equal(1, screenshots); - // The snapshot spent 150 ms and the step 350: the screenshot ended at the 500 ms of the one budget, not 500 ms after its own start. - Assert.Equal(TimeSpan.FromMilliseconds(500), h.Clock.GetUtcNow() - started); + // The test may spend several steps before the engine makes the timer that ends the wait, so only the lower bound is exact: the budget never ends early. + Assert.True(h.Clock.GetUtcNow() - started >= TimeSpan.FromMilliseconds(500)); } }