public async Task ShouldThrowServiceUnreachableExceptionWhenAllEndpointsTimeout() { using (var httpTest = new HttpTest()) { // Two subsequent calls should result in a server error 5xx httpTest.SimulateTimeout(); httpTest.SimulateTimeout(); var client = new MultiplexedRestClient(_authenticator, "dummy", new[] { new Uri("https://dummy1"), new Uri("https://dummy2") }); await Assert.ThrowsAsync <ServiceUnreachableException>(async() => await client.InvokeAsync(HttpMethod.Get, "dummy")); } }
public void Watch_ShouldRetryOnTimeoutException() { using (var http = new HttpTest()) { http.SimulateTimeout() .SimulateTimeout() .SimulateTimeout() .RespondWithJson(Fixtures.Watch.DefaultResponse); Etcd.ClientFor(Fixtures.EtcdUrl.ToUri()) .Watch(Fixtures.Watch.Path) .SubscribeFor(1) .Wait(); http.Should() .HaveCalled( Fixtures.EtcdUrl .AppendPathSegment(Constants.Etcd.Path_Keys) .AppendPathSegment(Fixtures.Watch.Path) .SetQueryParam(Constants.Etcd.Parameter_Wait, Constants.Etcd.Parameter_True) ) .WithVerb(HttpMethod.Get) .Times(4); } }
public void GetListOfFilesAndProcessTest(string ip, int numRecords) { var targetdir = Path.Combine(Directory.GetCurrentDirectory(), "Record"); var filesystem = new Mock <IFileSystemHelper>(); var blackVueDownloader = new PCL.BlackVueDownloader(filesystem.Object); var blackVueDownloaderNoMock = new PCL.BlackVueDownloader(); blackVueDownloaderNoMock.CreateDirectories(targetdir, targetdir); var httpTest = new HttpTest(); var list = blackVueDownloader.GetListOfFilesFromResponse(GenerateRecords(numRecords)); Assert.Equal(numRecords * 2, list.Count); BlackvueOptions options = new BlackvueOptions { Timeout = 0, IPAddress = ip }; // Success test for (var i = 0; i < numRecords * 4; i++) { httpTest.RespondWith("OK"); } blackVueDownloader.BlackVueDownloaderCopyStats.Clear(); blackVueDownloader.ProcessList(list, targetdir, targetdir, options); Assert.Equal(numRecords * 4, blackVueDownloader.BlackVueDownloaderCopyStats.Copied); // Ignored from above test // What happens with the above tests, is that it writes actual files to // BlackVueDownloader.Tests\bin\Debug\Record directory, // so there should be numrecords * 4 files there // And if we loop through again, they should all exist, and therefore be "ignored" // We need to do this with an unmocked version of the file system helper blackVueDownloaderNoMock.BlackVueDownloaderCopyStats.Clear(); blackVueDownloader.ProcessList(list, targetdir, targetdir, options); Assert.Equal(numRecords * 4, blackVueDownloaderNoMock.BlackVueDownloaderCopyStats.Ignored); // Fail test for (var i = 0; i < numRecords * 4; i++) { httpTest.RespondWith("FAILURE", 500); } blackVueDownloader.BlackVueDownloaderCopyStats.Clear(); blackVueDownloader.ProcessList(list, targetdir, targetdir, options); Assert.Equal(numRecords * 4, blackVueDownloader.BlackVueDownloaderCopyStats.Errored); // Timeout Fail test for (var i = 0; i < numRecords * 4; i++) { httpTest.SimulateTimeout(); } blackVueDownloader.BlackVueDownloaderCopyStats.Clear(); blackVueDownloader.ProcessList(list, targetdir, targetdir, options); Assert.Equal(numRecords * 4, blackVueDownloader.BlackVueDownloaderCopyStats.Errored); }
public async Task Should_Throw_TimeOut_Exception_When_Timing_Out() { httpClient.SimulateTimeout(); var api = new MandrillApi(""); Assert.Throws <TimeoutException>(async() => await api.Post <object>("", new SamplePayload())); }
public async Task SimpleTest_SucceedAsync() { // assign _httpTest.SimulateTimeout(); _httpTest.RespondWith(JsonConvert.SerializeObject("Bad"), 503); _httpTest.RespondWith(JsonConvert.SerializeObject("Ok"), 200); var flurlClient = new FlurlClient("http://example120.com/"); var response = await flurlClient.Request("api", "controller") .AllowHttpStatus(HttpStatusCode.OK) .WithRetryFuncAsync <string>(RetryFuncAsync) .RetryAsync(p => p.GetJsonAsync <string>()); response.Should().Be("Ok"); _httpTest.CallLog.Count.Should().Be(3); }
public async Task can_simulate_timeout_with_exception_handled() { HttpTest.SimulateTimeout(); var result = await "http://www.api.com" .ConfigureClient(c => c.OnError = call => call.ExceptionHandled = true) .GetAsync(); Assert.IsNull(result); }
public async Task can_get_null_json_when_timeout_and_exception_handled() { HttpTest.SimulateTimeout(); var data = await "http://api.com" .ConfigureRequest(c => c.OnError = call => call.ExceptionHandled = true) .GetJsonAsync <TestData>(); Assert.IsNull(data); }
public void ShouldThrowExceptionWithoutErrorObjectWhenApiCallFailsAndRequestIsNotCompleted() { _http.SimulateTimeout(); Func <Task> action = async() => await _apiClient.SendTextMessageAsync("123", "hello"); action .Should() .Throw <SendApiHttpException>() .Where(ex => ex.Error == null); }
public void ShouldThrowEtcdTimeoutException() { using (var http = new HttpTest()) { http.SimulateTimeout(); CallFixture.ShouldThrow <EtcdTimeoutException>() .And .IsTimeout.Should().BeTrue(); } }
public async Task can_simulate_timeout() { HttpTest.SimulateTimeout(); try { await "http://www.api.com".GetAsync(); Assert.Fail("Exception was not thrown!"); } catch (FlurlHttpTimeoutException ex) { Assert.IsInstanceOf <TaskCanceledException>(ex.InnerException); StringAssert.Contains("timed out", ex.Message); } }
public void GetListOfFilesAndProcessTest(string ip, int numRecords) { var filesystem = new Mock <IFileSystemHelper>(); var blackVueDownloader = new PCL.BlackVueDownloader(filesystem.Object); var blackVueDownloaderNoMock = new PCL.BlackVueDownloader(new FileSystemHelper()); var httpTest = new HttpTest(); var list = blackVueDownloader.GetListOfFilesFromResponse(GenerateRecords(numRecords)); Assert.Equal(numRecords * 2, list.Count); var copyStats = new BlackVueDownloaderCopyStats(); // Success test for (var i = 0; i < numRecords * 4; i++) { httpTest.RespondWith(200, "OK"); } copyStats.Clear(); blackVueDownloader.ProcessList(ip, list, ref copyStats); Assert.Equal(numRecords * 4, copyStats.Copied); // Ignored from above test // What happens with the above tests, is that it writes actual files to // BlackVueDownloader.Tests\bin\Debug\Record directory, // so there should be numrecords * 4 files there // And if we loop through again, they should all exist, and therefore be "ignored" // We need to do this with an unmocked version of the file system helper copyStats.Clear(); blackVueDownloaderNoMock.ProcessList(ip, list, ref copyStats); Assert.Equal(numRecords * 4, copyStats.Ignored); // Fail test for (var i = 0; i < numRecords * 4; i++) { httpTest.RespondWith(500, "FAILURE"); } copyStats.Clear(); blackVueDownloader.ProcessList(ip, list, ref copyStats); Assert.Equal(numRecords * 4, copyStats.Errored); // Timeout Fail test for (var i = 0; i < numRecords * 4; i++) { httpTest.SimulateTimeout(); } copyStats.Clear(); blackVueDownloader.ProcessList(ip, list, ref copyStats); Assert.Equal(numRecords * 4, copyStats.Errored); }
public async Task ShouldSucceedWhenAtLeastOneEndpointDoesNotTimeout() { using (var httpTest = new HttpTest()) { // Only the first call should result in a server error 5xx httpTest.SimulateTimeout(); var client = new MultiplexedRestClient(_authenticator, "dummy", new[] { new Uri("https://dummy1"), new Uri("https://dummy2") }); var response = await client.InvokeAsync(HttpMethod.Get, "dummy"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
public async void OrdersCheckOrdersAuthAsyncException() { _httpTest .SimulateTimeout() .SimulateTimeout(); await Assert.ThrowsAsync <EcwidHttpException>( async() => await _client.CheckOrdersTokenAsync()); _httpTest.ShouldHaveCalled($"{CheckOrdersUrl}&limit=1") .WithVerb(HttpMethod.Get) .Times(1); }
public async void OrdersCheckOrdersAuthAsync_Exception() { _httpTest .SimulateTimeout() .SimulateTimeout(); var exception = await Assert.ThrowsAsync <EcwidHttpException>( async() => await _client.CheckOrdersTokenAsync()); Assert.Contains("A task was canceled", exception.Message); _httpTest.ShouldHaveCalled($"{CheckOrdersUrl}&limit=1") .WithVerb(HttpMethod.Get) .Times(1); }
public async Task IsNotUp_Timeout() { using var httpTest = new HttpTest(); httpTest.SimulateTimeout(); // Logout httpTest.RespondWithJson(new { ok = true }); await using var client = new CouchClient("http://localhost"); var result = await client.IsUpAsync(); Assert.False(result); httpTest .ShouldHaveCalled($"http://localhost/_up") .WithVerb(HttpMethod.Get); }
public async Task RwsConnection_raises_an_exception_if_timeout_occurs() { var rwsConnection = new RwsConnection("innovate", "test", "password"); _httpTest.SimulateTimeout(); try { await rwsConnection.SendRequestAsync(new FakeRwsRequest()); } catch (RwsException ex) { Assert.AreEqual( "Connection timeout for https://innovate.mdsol.com/RaveWebServices/fakepath", ex.Message ); } }
public async Task RebuildCall_Is_Retried_On_Timeout() { // Arrange _httpTest.SimulateTimeout(); _httpTest.RespondWith(string.Empty, 200); // Act var outcome = await _classUnderTest.Run(_mockContext.Object, _mockLogger.Object); // Assert Assert.That(outcome, Is.EqualTo(ProcessingOutcome.Rebuilt)); _httpTest.ShouldHaveCalled(ApiUrl) .WithQueryParamValue("code", ApiKey) .Times(2); }
public async Task FileTypeDetectionCall_Is_Retried_On_Timeout() { // Arrange const string expectedFileType = "doc"; _httpTest.SimulateTimeout(); _httpTest.RespondWithJson(new { FileTypeName = expectedFileType }); // Act var outcome = await _classUnderTest.Run(_mockContext.Object, _mockLogger.Object); // Assert Assert.That(outcome, Is.EqualTo(expectedFileType)); _httpTest.ShouldHaveCalled(ApiUrl) .WithHeader("x-api-key", ApiKey) .Times(2); }
public void WhenMakingCallWithTimeoutErrorMessageShouldBeSet() { _httpTest.SimulateTimeout(); bool errorWasCalled = false; _sut.PropertyChanged += (sender, args) => { _output.WriteLine(args.PropertyName); if (args.PropertyName == nameof(MainViewModel.ErrorMessage)) { errorWasCalled = true; } }; _sut.GoForward.Execute(null); Thread.Sleep(1000); // To wait for events, should ideally be solved in a better way PrintAllCalls(); errorWasCalled.ShouldBe(true); }
public async Task can_simulate_timeout_with_exception_handled() { HttpTest.SimulateTimeout(); var exceptionCaught = false; var resp = await "http://api.com" .ConfigureRequest(c => c.OnError = call => { exceptionCaught = true; var ex = call.Exception as TaskCanceledException; Assert.NotNull(ex); Assert.IsInstanceOf <TimeoutException>(ex.InnerException); call.ExceptionHandled = true; }) .GetAsync(); Assert.IsNull(resp); Assert.IsTrue(exceptionCaught); }
public void CantFindCameraTest(string ip) { var blackVueDownloader = new PCL.BlackVueDownloader(); using (var httpTest = new HttpTest()) { httpTest.SimulateTimeout(); try { blackVueDownloader.QueryCameraForFileList(ip); } catch (Exception e) { Assert.StartsWith("One or more errors occurred.", e.Message); } httpTest.ShouldHaveCalled($"http://{ip}/blackvue_vod.cgi"); } }
public async Task WhenUnhandledTimeout_Throws() { using (var httpTest = new HttpTest()) { // Arrange var baseUri = "http://localhost"; httpTest.SimulateTimeout(); // Act var response = await Assert.ThrowsAsync <FlurlHttpTimeoutException>( () => baseUri .GetAsync()); // Assert httpTest.ShouldHaveCalled($"http://localhost") .WithVerb(HttpMethod.Get) .Times(1); response.Message.Should().BeEquivalentTo( $"Call timed out: GET http://localhost"); } }
public async Task GetGetCardSuperTypesAsync_Exception_Failure() { // arrange _mockRateLimit.Setup(x => x.IsTurnedOn).Returns(false); using var httpTest = new HttpTest(); httpTest.SimulateTimeout(); var service = new CardService( _mockHeaderManager.Object, _mockModelMapper.Object, ApiVersion.V1, _mockRateLimit.Object); // act var result = await service.GetCardSuperTypesAsync(); // assert Assert.False(result.IsSuccess); _mockRepository.VerifyAll(); }
public async Task AuthTimeoutTest(string ClientID, string ClientSecret, string Email, string Password, string Token) { var client = new Client(); var auth = new Auth { ClientID = ClientID, ClientSecret = ClientSecret, Email = Email, Password = Password }; using (var httpTest = new HttpTest()) { httpTest.SimulateTimeout(); try { var t = await client.Authorize(auth); } catch (Exception e) { Assert.True(e.Message.Contains("timeout")); } httpTest.ShouldHaveCalled(ServiceURL.AuthURL); } }
public void AndGivenTheServiceIsUnavailable() { _httpClient = new HttpTest(); _httpClient.SimulateTimeout(); }
private void GivenTheBrokerWillTimeOut() { _httpTest.SimulateTimeout(); }