Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/E2E/Locator/LocatorEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ internal async Task<SemanticNode> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,21 @@ private static Screen LocatingScreen(List<Func<TimeSpan, Task<IReadOnlyList<Sema
[Fact]
public async Task Keeps_a_resolve_that_hung_with_budget_to_spare_a_timeout_never_a_missing_node()
{
// The reads move a fake clock, so a loaded runner cannot shift the deadline the hang runs into.
var clock = new SteppingTime();
var calls = 0;
var screen = LocatingScreen(
[
budget => { 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<TestException>(() => 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<TestException>(() => resolving);

Assert.Equal("ACTION_FAILED", error.Code);
Assert.Equal(2, calls);
Expand Down
7 changes: 7 additions & 0 deletions tests/E2E.Tests/LocatorEngine/SlowLocate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public static Task<IReadOnlyList<SemanticNode>> AnswerAsync(FakeTimeProvider clo
return Task.FromResult(nodes);
}

/// <summary>A locate that never answers on its own, on a fake clock: it takes the whole <paramref name="budget"/> and ends with <c>OPERATION_TIMEOUT</c>.</summary>
public static Task<IReadOnlyList<SemanticNode>> HangAsync(FakeTimeProvider clock, TimeSpan budget)
{
clock.Advance(budget);
return Task.FromException<IReadOnlyList<SemanticNode>>(new EngineException(EngineErrorCodes.OperationTimeout, "operation timed out", retryable: false));
}

/// <summary>A locate that never answers on its own, ended at <paramref name="budget"/>.</summary>
public static async Task<IReadOnlyList<SemanticNode>> HangAsync(TimeSpan budget)
{
Expand Down
8 changes: 8 additions & 0 deletions tests/E2E.Tests/SteppingTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,6 +34,8 @@ public override ITimer CreateTimer(TimerCallback callback, object? state, TimeSp
/// <summary>Runs the clock until <paramref name="pending"/> ends, then returns its outcome.</summary>
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.
Expand All @@ -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;
Expand Down
Loading