public void ShouldSendRequestsEvenIfPreviousFailed() { var service = new MockServiceBuilder().Build(); service.Setup(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>())).Throws <Exception>(); var logsReporter = new LogsReporter(_testReporter.Object, service.Object, _extensionManager, _requestExecuter, _logRequestAmender.Object); logsReporter.BatchCapacity = 1; for (int i = 0; i < 2; i++) { logsReporter.Log(new CreateLogItemRequest { Text = "a", Time = DateTime.UtcNow }); } try { logsReporter.Sync(); } catch (Exception) { } service.Verify(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>()), Times.Exactly(2)); }
public void ShouldBeThreadSafeWhenSchedulingLogRequests() { var logItemRequestTexts = new List <string>(); var service = new MockServiceBuilder().Build(); service.Setup(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>())) .Callback <CreateLogItemRequest[]>(rqs => { foreach (var rq in rqs) { logItemRequestTexts.Add(rq.Text); } }) .Returns(() => Task.FromResult(new Client.Abstractions.Responses.LogItemsCreatedResponse())); var logsReporter = new LogsReporter(_testReporter.Object, service.Object, _extensionManager, _requestExecuter, _logRequestAmender.Object); Parallel.For(0, 1000, (i) => logsReporter.Log(new CreateLogItemRequest { Text = i.ToString(), Time = DateTime.UtcNow })); logsReporter.Sync(); service.Verify(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>()), Times.Exactly(100)); logItemRequestTexts.Should().HaveCount(1000); logItemRequestTexts.Should().OnlyHaveUniqueItems(); }
public void ShouldSendAsSeparateRequestPerLogWithAttachmentIncludingWithoutAttachment() { var service = new MockServiceBuilder().Build(); var logsReporter = new LogsReporter(_testReporter.Object, service.Object, _extensionManager, _requestExecuter, _logRequestAmender.Object); var withoutAttachment = new CreateLogItemRequest { Text = "a", Time = DateTime.UtcNow }; var withAttachment = new CreateLogItemRequest { Text = "a", Time = DateTime.UtcNow, Attach = new LogItemAttach() }; logsReporter.Log(withAttachment); logsReporter.Log(withoutAttachment); logsReporter.Log(withAttachment); logsReporter.Log(withoutAttachment); logsReporter.Sync(); service.Verify(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>()), Times.Exactly(2)); }
public void ShouldSendBatchedRequests() { var service = new MockServiceBuilder().Build(); var logsReporter = new LogsReporter(_testReporter.Object, service.Object, _extensionManager, _requestExecuter, _logRequestAmender.Object); for (int i = 0; i < 50; i++) { logsReporter.Log(new CreateLogItemRequest { Text = "a", Time = DateTime.UtcNow }); } logsReporter.Sync(); service.Verify(s => s.LogItem.CreateAsync(It.IsAny <CreateLogItemRequest[]>()), Times.Exactly(5)); }