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
15 changes: 11 additions & 4 deletions src/Orleans.Reminders.TestKit/ReminderTableRetryPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,23 @@ internal static async Task<T> ExecuteUntilAsync<T>(
while (true)
{
var remaining = timeout - stopwatch.Elapsed;
if (remaining <= TimeSpan.Zero)
if (attempts > 0 && remaining <= TimeSpan.Zero)
{
ThrowTimeout();
}

attempts++;
try
{
var value = await operation().WaitAsync(remaining);
attempts++;
var attempt = operation();
remaining = timeout - stopwatch.Elapsed;
if (remaining <= TimeSpan.Zero)
{
lastException = new TimeoutException("The retry timeout elapsed while starting the operation.");
ThrowTimeout();
}

var value = await attempt.WaitAsync(remaining);
lastException = null;
lastObservation = describe(value);
if (succeeded(value))
Expand All @@ -115,7 +123,6 @@ internal static async Task<T> ExecuteUntilAsync<T>(
}
catch (Exception exception) when (exception is not ReminderConformanceException)
{
attempts++;
lastException = exception;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,56 @@ public async Task UniformMutationPolicy_DetectsPersistentContentionWithLastExcep
public async Task UniformPolicy_HardBoundsTheFirstAttempt()
{
var never = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
var invocations = 0;

var exception = await Assert.ThrowsAsync<ReminderConformanceException>(() =>
ReminderTableRetryPolicy.ExecuteUntilAsync(
() => never.Task,
() =>
{
invocations++;
return never.Task;
},
_ => true,
"Blocked",
"ReadGuarantee",
"ReadRow",
"a completed read",
value => value,
"read convergence",
TimeSpan.FromMilliseconds(40),
TimeSpan.FromTicks(1),
TimeSpan.FromMilliseconds(5)));

Assert.Equal(1, invocations);
Assert.Contains("attempts=1", exception.Message, StringComparison.Ordinal);
Assert.Contains("Last exception: System.TimeoutException", exception.Message, StringComparison.Ordinal);
}

[Fact]
public async Task UniformPolicy_EnforcesDeadlineAfterStartingFirstAttempt()
{
var invocations = 0;

var exception = await Assert.ThrowsAsync<ReminderConformanceException>(() =>
ReminderTableRetryPolicy.ExecuteUntilAsync(
() =>
{
invocations++;
Thread.Sleep(TimeSpan.FromMilliseconds(20));
return Task.FromResult("late-success");
},
_ => true,
"DelayedStart",
"ReadGuarantee",
"ReadRow",
"a result within the deadline",
value => value,
"read convergence",
TimeSpan.FromMilliseconds(1),
TimeSpan.FromMilliseconds(5)));

Assert.Equal(1, invocations);
Assert.Contains("attempts=1", exception.Message, StringComparison.Ordinal);
Assert.Contains("Last observation: <no completed attempt>", exception.Message, StringComparison.Ordinal);
Assert.Contains("Last exception: System.TimeoutException", exception.Message, StringComparison.Ordinal);
}

Expand Down
Loading