public SendWebHookWorkItemsAsync ( IEnumerable |
||
workItems | IEnumerable |
|
return | System.Threading.Tasks.Task |
public async Task SendWebHook_StopsOnLastLastFailureOrFirstSuccessAndFirstGone(TimeSpan[] delays, Func <HttpRequestMessage, int, Task <HttpResponseMessage> > handler, int expectedOffset, SendResult expectedResult) { // Arrange var actualResult = SendResult.None; var done = new ManualResetEvent(initialState: false); WebHookWorkItem final = null; var actualRetries = 0; _sender = new TestDataflowWebHookSender(_loggerMock.Object, delays, _options, _httpClient, onWebHookRetry: item => { actualRetries++; }, onWebHookSuccess: item => { final = item; actualResult = SendResult.Success; done.Set(); }, onWebHookGone: item => { final = item; actualResult = SendResult.Gone; done.Set(); }, onWebHookFailure: item => { final = item; actualResult = SendResult.Failure; done.Set(); }); _handlerMock.Handler = handler; var notification = new NotificationDictionary("a1", data: null); var webHook = WebHookManagerTests.CreateWebHook(); var workItem = new WebHookWorkItem(webHook, new[] { notification }) { Id = "1234567890", }; // Act await _sender.SendWebHookWorkItemsAsync(new[] { workItem }); done.WaitOne(); // Assert var expectedRetries = expectedResult == SendResult.Failure ? Math.Max(0, expectedOffset - 1) : expectedOffset; Assert.Equal(expectedRetries, actualRetries); Assert.Equal(expectedResult, actualResult); Assert.Equal(expectedOffset, final.Offset); }
public async Task SendWebHook_StopsOnLastLastFailureOrFirstSuccessAndFirstGone(TimeSpan[] delays, Func <HttpRequestMessage, int, Task <HttpResponseMessage> > handler, int expected) { // Arrange ManualResetEvent done = new ManualResetEvent(initialState: false); WebHookWorkItem success = null, failure = null; _sender = new DataflowWebHookSender(_loggerMock.Object, delays, _options, _httpClient, onWebHookSuccess: item => { success = item; done.Set(); }, onWebHookFailure: item => { failure = item; done.Set(); }); _handlerMock.Handler = handler; NotificationDictionary notification = new NotificationDictionary("a1", data: null); WebHook webHook = WebHookManagerTests.CreateWebHook(); WebHookWorkItem workItem = new WebHookWorkItem(webHook, new[] { notification }) { Id = "1234567890", }; // Act await _sender.SendWebHookWorkItemsAsync(new[] { workItem }); done.WaitOne(); // Assert if (expected >= 0) { Assert.Equal(expected, success.Offset); } else { Assert.Equal(Math.Abs(expected), failure.Offset); } }
public async Task SendWebHook_StopsOnLastLastFailureOrFirstSuccessAndFirstGone(TimeSpan[] delays, Func<HttpRequestMessage, int, Task<HttpResponseMessage>> handler, int expected) { // Arrange ManualResetEvent done = new ManualResetEvent(initialState: false); WebHookWorkItem success = null, failure = null; _sender = new DataflowWebHookSender(_loggerMock.Object, delays, _options, _httpClient, onWebHookSuccess: item => { success = item; done.Set(); }, onWebHookFailure: item => { failure = item; done.Set(); }); _handlerMock.Handler = handler; NotificationDictionary notification = new NotificationDictionary("a1", data: null); WebHook webHook = WebHookManagerTests.CreateWebHook(); WebHookWorkItem workItem = new WebHookWorkItem(webHook, new[] { notification }) { Id = "1234567890", }; // Act await _sender.SendWebHookWorkItemsAsync(new[] { workItem }); done.WaitOne(); // Assert if (expected >= 0) { Assert.Equal(expected, success.Offset); } else { Assert.Equal(Math.Abs(expected), failure.Offset); } }
public async Task SendWebHook_StopsOnLastLastFailureOrFirstSuccessAndFirstGone(TimeSpan[] delays, Func<HttpRequestMessage, int, Task<HttpResponseMessage>> handler, int expectedOffset, SendResult expectedResult) { // Arrange SendResult actualResult = SendResult.None; ManualResetEvent done = new ManualResetEvent(initialState: false); WebHookWorkItem final = null; int actualRetries = 0; _sender = new TestDataflowWebHookSender(_loggerMock.Object, delays, _options, _httpClient, onWebHookRetry: item => { actualRetries++; }, onWebHookSuccess: item => { final = item; actualResult = SendResult.Success; done.Set(); }, onWebHookGone: item => { final = item; actualResult = SendResult.Gone; done.Set(); }, onWebHookFailure: item => { final = item; actualResult = SendResult.Failure; done.Set(); }); _handlerMock.Handler = handler; NotificationDictionary notification = new NotificationDictionary("a1", data: null); WebHook webHook = WebHookManagerTests.CreateWebHook(); WebHookWorkItem workItem = new WebHookWorkItem(webHook, new[] { notification }) { Id = "1234567890", }; // Act await _sender.SendWebHookWorkItemsAsync(new[] { workItem }); done.WaitOne(); // Assert int expectedRetries = expectedResult == SendResult.Failure ? Math.Max(0, expectedOffset - 1) : expectedOffset; Assert.Equal(expectedRetries, actualRetries); Assert.Equal(expectedResult, actualResult); Assert.Equal(expectedOffset, final.Offset); }