public async Task TestAuthExceptionThrownFromDropClientConstructor(int numOfAuthFailures, bool operationReturnsResult) { Action <int> maybeThrow = (cnt) => { // first time it must succeed; in real use cases, failing the first time around would mean that the // user indeed is not authorized, in which case we should fail. // At some point later, say, session token expired, so Auth exception is thrown. if (cnt > 1 && cnt <= numOfAuthFailures + 1) { TestLogger.Verbose("cnt = {0}, throwing", cnt); ThrowUnauthorizedException(); } }; int counter = 0; var reloadingClient = new ReloadingDropServiceClient( logger: TestLogger, clientConstructor: () => { maybeThrow(++counter); return(new MockDropServiceClient(dropOperation: () => { maybeThrow(++counter); })); }); await CallDropOperationAsync(reloadingClient, operationReturnsResult); XAssert.AreEqual(2, reloadingClient.Reloader.CurrentVersion); }
private Task CallDropOperationAsync(ReloadingDropServiceClient reloadingClient, bool operationReturnsResult) { return(operationReturnsResult // test Task<U> RetryAsync<U> ? reloadingClient.CreateAsync("name", true, null, false, CancellationToken.None) // test Task RetryAsync : reloadingClient.DownloadAsync("name", null, CancellationToken.None, false)); }
public async Task TestPermanentAuthException(bool operationReturnsResult) { var retryIntervals = new[] { TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(20) }; var reloadingClient = new ReloadingDropServiceClient( logger: TestLogger, retryIntervals: retryIntervals, clientConstructor: () => new MockDropServiceClient(dropOperation: ThrowUnauthorizedException)); await Assert.ThrowsAsync <VssUnauthorizedException>(() => CallDropOperationAsync(reloadingClient, operationReturnsResult)); XAssert.AreEqual(retryIntervals.Length + 1, reloadingClient.Reloader.CurrentVersion); }
public async Task TestNoAuthExceptionThrownMeansNoReloading(bool operationReturnsResult) { var reloadingClient = new ReloadingDropServiceClient( logger: TestLogger, clientConstructor: () => new MockDropServiceClient(dropOperation: () => { })); await CallDropOperationAsync(reloadingClient, operationReturnsResult); XAssert.AreEqual(1, reloadingClient.Reloader.CurrentVersion); await CallDropOperationAsync(reloadingClient, operationReturnsResult); await CallDropOperationAsync(reloadingClient, operationReturnsResult); await CallDropOperationAsync(reloadingClient, operationReturnsResult); XAssert.AreEqual(1, reloadingClient.Reloader.CurrentVersion); }
public async Task TestAuthExceptionThrownFromDropOperation(int numOfAuthFailures, bool operationReturnsResult) { int counter = 0; var reloadingClient = new ReloadingDropServiceClient( logger: TestLogger, clientConstructor: () => new MockDropServiceClient( dropOperation: () => { counter++; if (counter <= numOfAuthFailures) { ThrowUnauthorizedException(); } })); await CallDropOperationAsync(reloadingClient, operationReturnsResult); XAssert.AreEqual(numOfAuthFailures + 1, reloadingClient.Reloader.CurrentVersion); }
private Task CallDropOperationAsync(ReloadingDropServiceClient reloadingClient) { return(reloadingClient.CreateAsync("name", true, null, false, CancellationToken.None)); }