Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored the library #21

Merged
merged 12 commits into from Jan 29, 2019

Fixed memory leak

  • Loading branch information
Jiri Tomek
Jiri Tomek committed Jan 29, 2019
commit d967b8e7d48b48588d8678370c935ed570cb7d61
@@ -239,6 +239,42 @@ public void SentBulkIsLimitedByMaxBulkSize()
}, "correct messages should be sent");
}

[Fact]
public void NextBulkSizeLimitationStartsFromZero()
{
// message of 10 bytes, buffer for 10 messages = 100 bytes
// max bulk size se to 30 -> bulk size should be limited by this number
_config.MaxBulkSizeBytes = 30;
_config.BufferSize = 10;
var oneMessageSize = 10;
var oneMessage = new String('x', oneMessageSize);

ExpectSends(3);

var buffer = new LogglyAsyncBuffer(_config, _clientMock.Object);

// +7 messages so that 3 bulks by 3 messages are sent before number of messages goes below buffer size
for (int i = 0; i < _config.BufferSize + 7; i++)
{
buffer.BufferForSend(oneMessage);
}

_allSentEvent.Wait(MaxWaitTime).Should().BeTrue("messages should be sent");

_sentMessages.Should().BeEquivalentTo(new[]
{
oneMessage,
oneMessage,
oneMessage,
oneMessage,
oneMessage,
oneMessage,
oneMessage,
oneMessage,
oneMessage,
}, "correct messages should be sent");
}

private void ExpectSends(int numberOfSends)
{
_allSentEvent = new CountdownEvent(numberOfSends);
@@ -79,7 +79,6 @@ private void DoSend()
var handles = new WaitHandle[] { _stopEvent, _readyToSendEvent, _flushingEvent };

int triggeredBy;
int bulkSize = 0;
while ((triggeredBy = WaitHandle.WaitAny(handles, _config.SendInterval)) != 0)
{
// allow sending partial buffer only when it was triggered by timeout or flush
@@ -91,6 +90,7 @@ private void DoSend()

_sendInProgress = true;
int sendBufferIndex = 0;
int bulkSize = 0;
while (sendBufferIndex < sendBuffer.Length
&& _messages.TryPeek(out var message)
&& bulkSize + message.Length <= _config.MaxBulkSizeBytes)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.