Skip to content
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

Introduce an exponential retry for service timing issue causing flakey Live tests #15159

Merged
2 commits merged into from
Sep 15, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,13 @@ public async Task GetPropertiesReturnsProperties()

await service.SetPropertiesAsync(responseToChange).ConfigureAwait(false);

// Wait 20 sec if on Live mode to ensure properties are updated in the service
// Minimum time: Sync - 20 sec; Async - 12 sec

if (Mode != RecordedTestMode.Playback)
{
await Task.Delay(20000);
}

// Get configured properties
// A delay is required to ensure properties are updated in the service

TableServiceProperties changedResponse = await service.GetPropertiesAsync().ConfigureAwait(false);
TableServiceProperties changedResponse = await RetryUntilExpectedResponse(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This delay feels a bit aggressive or is the service that slow?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's that slow - the live test was failing with a hard coded 20 second delay. 😮

async () => await service.GetPropertiesAsync().ConfigureAwait(false),
result => result.Value.Logging.Read == responseToChange.Logging.Read,
15000).ConfigureAwait(false);

// Test each property

Expand Down
21 changes: 21 additions & 0 deletions sdk/tables/Azure.Data.Tables/tests/TableServiceLiveTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,27 @@ protected async Task<TResult> CosmosThrottleWrapper<TResult>(Func<Task<TResult>>
}
}

protected async Task<TResult> RetryUntilExpectedResponse<TResult>(Func<Task<TResult>> action, Func<TResult, bool> equalityAction, int initialDelay)
{
int retryCount = 0;
int delay = initialDelay;
while (true)
{
var actual = await action().ConfigureAwait(false);

if (++retryCount > 3 || equalityAction(actual))
{
return actual;
}
// Disable retry throttling in Playback mode.
if (Mode != RecordedTestMode.Playback)
{
await Task.Delay(delay);
delay *= 2;
}
}
}

protected async Task CreateTestEntities<T>(List<T> entitiesToCreate) where T : class, ITableEntity, new()
{
foreach (var entity in entitiesToCreate)
Expand Down