Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions tests/E2E.Tests/LocatorWaitFor/ASlowLastReadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Modified by Dario Kondratiuk.
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;
using E2E.Engine;
using E2E.Tests.LocatorEngine;

Expand All @@ -16,35 +15,40 @@ public sealed class ASlowLastReadTests
{
private static readonly SemanticNode Banner = new() { Ref = "banner", Role = "alert", Name = "Saved", TestId = "banner" };

/// <summary>A screen whose every read takes 350 ms, bounded by its operation's budget, and whose banner shows up at 1050 ms.</summary>
private static Locator SlowScreen()
/// <summary>
/// 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.
/// </summary>
private static Locator SlowScreen(SteppingTime clock)
{
var clock = Stopwatch.StartNew();
var screen = new Screen(
_ => Task.FromResult(new Observation { Route = "/", Roots = [] }),
(_, _, _) => Task.CompletedTask,
() => CancellationToken.None,
() => { },
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");
}

[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());
}
}
Loading