public async Task InvokeAsync_TimesOutAndNoFallback_ThrowsCommandException() { var command = new TimingOutWithoutFallbackCommand(TimeSpan.FromMilliseconds(100)); try { await command.InvokeAsync(); } catch (CommandFailedException) { return; // Expected. } AssertX.FailExpectedException(); }
public async Task InvokeAsync_WithTimeout_TimesOutAndThrowsCommandException() { var command = new TimingOutWithoutFallbackCommand(Timeout); try { await command.InvokeAsync(); } catch (CommandFailedException e) { Assert.True(e.GetBaseException() is OperationCanceledException); return; } AssertX.FailExpectedException(); }
public async Task InvokeAsync_OperationCanceledException() { var mockStats = new Mock<IStats>(); var mockMetricEvents = new Mock<IMetricEvents>(); var command = new TimingOutWithoutFallbackCommand(TimeSpan.FromMilliseconds(100)) { Stats = mockStats.Object, MetricEvents = mockMetricEvents.Object, }; var e = await Assert.ThrowsAsync<CommandTimeoutException>(command.InvokeAsync); Assert.True(e.GetBaseException() is OperationCanceledException); mockStats.Verify(m => m.Elapsed("mjolnir command test.TimingOutWithoutFallback total", "TimedOut", It.IsAny<TimeSpan>()), Times.Once); mockStats.Verify(m => m.Elapsed("mjolnir command test.TimingOutWithoutFallback execute", "TimedOut", It.IsAny<TimeSpan>()), Times.Once); mockMetricEvents.Verify(m => m.CommandInvoked("test.TimingOutWithoutFallback", It.IsAny<double>(), It.IsAny<double>(), "TimedOut", "throw")); mockMetricEvents.Verify(m => m.RejectedByBulkhead(It.IsAny<string>(), It.IsAny<string>()), Times.Never); }
public async Task InvokeAsync_OperationCanceledException() { var mockStats = new Mock<IStats>(); var command = new TimingOutWithoutFallbackCommand(TimeSpan.FromMilliseconds(100)) { Stats = mockStats.Object, }; try { await command.InvokeAsync(); } catch (CommandFailedException e) { Assert.True(e.GetBaseException() is OperationCanceledException); mockStats.Verify(m => m.Elapsed("mjolnir command test.TimingOutWithoutFallback total", "Canceled", It.IsAny<TimeSpan>()), Times.Once); mockStats.Verify(m => m.Elapsed("mjolnir command test.TimingOutWithoutFallback execute", "Canceled", It.IsAny<TimeSpan>()), Times.Once); return; // Expected. } AssertX.FailExpectedException(); }
public async Task InvokeAsync_OperationCanceledException() { var mockStats = new Mock <IStats>(); var command = new TimingOutWithoutFallbackCommand(TimeSpan.FromMilliseconds(100)) { Stats = mockStats.Object, }; try { await command.InvokeAsync(); } catch (CommandFailedException e) { Assert.True(e.GetBaseException() is OperationCanceledException); mockStats.Verify(m => m.Elapsed("mjolnir command test.TimingOutWithoutFallback total", "Canceled", It.IsAny <TimeSpan>()), Times.Once); mockStats.Verify(m => m.Elapsed("mjolnir command test.TimingOutWithoutFallback execute", "Canceled", It.IsAny <TimeSpan>()), Times.Once); return; // Expected. } AssertX.FailExpectedException(); }
public async Task InvokeAsync_TimesOutAndNoFallback_ThrowsCommandException() { var command = new TimingOutWithoutFallbackCommand(TimeSpan.FromMilliseconds(100)); await Assert.ThrowsAsync<CommandTimeoutException>(() => command.InvokeAsync()); }