Skip to content

Commit 3bbe65d

Browse files
authored
Introduce an exponential retry for service timing issue causing flakey Live tests (Azure#15159)
see https://dev.azure.com/azure-sdk/internal/_build/results?buildId=537514&view=results
1 parent def8df1 commit 3bbe65d

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

sdk/tables/Azure.Data.Tables/tests/TableServiceClientLiveTests.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,13 @@ public async Task GetPropertiesReturnsProperties()
245245

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

248-
// Wait 20 sec if on Live mode to ensure properties are updated in the service
249-
// Minimum time: Sync - 20 sec; Async - 12 sec
250-
251-
if (Mode != RecordedTestMode.Playback)
252-
{
253-
await Task.Delay(20000);
254-
}
255-
256248
// Get configured properties
249+
// A delay is required to ensure properties are updated in the service
257250

258-
TableServiceProperties changedResponse = await service.GetPropertiesAsync().ConfigureAwait(false);
251+
TableServiceProperties changedResponse = await RetryUntilExpectedResponse(
252+
async () => await service.GetPropertiesAsync().ConfigureAwait(false),
253+
result => result.Value.Logging.Read == responseToChange.Logging.Read,
254+
15000).ConfigureAwait(false);
259255

260256
// Test each property
261257

sdk/tables/Azure.Data.Tables/tests/TableServiceLiveTestsBase.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,27 @@ protected async Task<TResult> CosmosThrottleWrapper<TResult>(Func<Task<TResult>>
262262
}
263263
}
264264

265+
protected async Task<TResult> RetryUntilExpectedResponse<TResult>(Func<Task<TResult>> action, Func<TResult, bool> equalityAction, int initialDelay)
266+
{
267+
int retryCount = 0;
268+
int delay = initialDelay;
269+
while (true)
270+
{
271+
var actual = await action().ConfigureAwait(false);
272+
273+
if (++retryCount > 3 || equalityAction(actual))
274+
{
275+
return actual;
276+
}
277+
// Disable retry throttling in Playback mode.
278+
if (Mode != RecordedTestMode.Playback)
279+
{
280+
await Task.Delay(delay);
281+
delay *= 2;
282+
}
283+
}
284+
}
285+
265286
protected async Task CreateTestEntities<T>(List<T> entitiesToCreate) where T : class, ITableEntity, new()
266287
{
267288
foreach (var entity in entitiesToCreate)

0 commit comments

Comments
 (0)