Repository navigation
Run the mobile shared-budget observe test on a clock the test moves #1141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -658,23 +658,31 @@ 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<JsonNode?>(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<EngineException>(() => session.ObserveAsync(new ObserveOptions { Pixels = true }, TimeSpan.FromMilliseconds(500), CancellationToken.None)); | ||
| var started = h.Clock.GetUtcNow(); | ||
| var observing = Assert.ThrowsAsync<EngineException>(() => session.ObserveAsync(new ObserveOptions { Pixels = true }, TimeSpan.FromMilliseconds(500), CancellationToken.None)); | ||
| await shot.Task; | ||
| await h.Clock.SpendUntil(observing, TimeSpan.FromMilliseconds(350)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| var failure = await observing; | ||
| Assert.Equal("OPERATION_TIMEOUT", failure.Code); | ||
| Assert.Equal(1, screenshots); | ||
| Assert.True(DateTimeOffset.UtcNow - started < TimeSpan.FromSeconds(3)); | ||
| // 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)); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: hardkoded/e2e-dotnet
Length of output: 8270
Script executed:
Repository: hardkoded/e2e-dotnet
Length of output: 11559
Script executed:
Repository: hardkoded/e2e-dotnet
Length of output: 8699
Script executed:
Repository: hardkoded/e2e-dotnet
Length of output: 1766
Bound the screenshot wait so a failed observation does not hang.
If
ObserveAsyncthrows before it sends the screenshot,await shot.Tasknever completes. No test-level timeout ends that wait. Under--blame-hang-timeout 5min CI, the run stops only after five minutes. Race the wait againstobserving, then assert that the screenshot was sent.As per coding guidelines, C# changes need checks for "bounded waits". The unbounded
await shot.Taskviolates that check.Suggested fix
Committable suggestion