public void Flush_ReturnsTrueIfAllMessagesAreSent() { _config.BufferSize = 3; var buffer = new LogglyAsyncBuffer(_config, _clientMock.Object); buffer.BufferForSend("test message 1"); buffer.BufferForSend("test message 2"); var result = buffer.Flush(MaxWaitTime); result.Should().BeTrue(); }
public void Flush_ReturnsFalseIfNotAllMessagesAreSent() { _config.BufferSize = 3; ExpectSends(1); var buffer = new LogglyAsyncBuffer(_config, _clientMock.Object); // block sending _allowSendingEvent.Reset(); buffer.BufferForSend("test message 1"); buffer.BufferForSend("test message 2"); var result = buffer.Flush(TimeSpan.FromSeconds(1)); result.Should().BeFalse(); }
public void Flush_FlushesPendingMessages() { _config.BufferSize = 3; ExpectSends(1); var buffer = new LogglyAsyncBuffer(_config, _clientMock.Object); buffer.BufferForSend("test message 1"); buffer.BufferForSend("test message 2"); buffer.Flush(MaxWaitTime); _sentMessages.Should().BeEquivalentTo(new[] { "test message 1", "test message 2" }, "pending messages should be sent"); }
public void DiscardsOldestMessagesIfMaxQueueSizeIsSet() { _config.MaxLogQueueSize = 5; ExpectSends(1); var buffer = new LogglyAsyncBuffer(_config, _clientMock.Object); _allowSendingEvent.Reset(); // block after first message sending buffer.BufferForSend("test message 1"); // trigger send without waiting for full buffer buffer.Flush(TimeSpan.FromMilliseconds(10)); _allSentEvent.Wait(MaxWaitTime).Should().BeTrue("first message should be already sent"); ExpectSends(1); buffer.BufferForSend("test message 2"); buffer.BufferForSend("test message 3"); buffer.BufferForSend("test message 4"); buffer.BufferForSend("test message 5"); buffer.BufferForSend("test message 6"); buffer.BufferForSend("test message 7"); buffer.BufferForSend("test message 8"); buffer.BufferForSend("test message 9"); // now allow sending the rest _allowSendingEvent.Set(); _allSentEvent.Wait(MaxWaitTime).Should().BeTrue("messages should be sent"); _sentMessages.Should().BeEquivalentTo(new[] { // message 1 initiated whole sending so it was sent "test message 1", // messages 2-4 were dropped because they exceeded buffer size when message 1 was being sent "test message 5", "test message 6", "test message 7", "test message 8", "test message 9", }, "correct messages should be sent"); }