Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasticFiasco committed Mar 17, 2024
1 parent ca130cb commit ec88cce
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

using System;
using Serilog.Core;
using Serilog.Debugging;
using Serilog.Events;
using Serilog.Formatting;
using Serilog.Sinks.Http.Private.IO;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Serilog.Sinks.Http.BatchFormatters;
using Serilog.Sinks.Http.HttpClients;
Expand Down Expand Up @@ -146,4 +147,90 @@ public async Task RespectLogEventLimitBytes()
webServerFixture.GetAllBatches(testId).ShouldBeEmpty();
webServerFixture.GetAllEvents(testId).ShouldBeEmpty();
}

[Fact]
public void SendStoredLogEventsGivenFlushOnClose()
{
// Arrange
var testId = $"SendStoredLogEventsGivenFlushOnClose_{Guid.NewGuid()}";

// Create 10 log events
var logEvents = Enumerable
.Range(1, 10)
.Select(number => Some.LogEvent("Event {number}", number))
.ToArray();

var period = TimeSpan.FromSeconds(5);
var flushOnClose = true;

var sink = new TimeRolledDurableHttpSink(
requestUri: webServerFixture.RequestUri(testId),
bufferBaseFileName: Path.Combine("logs", testId),
bufferRollingInterval: BufferRollingInterval.Day,
bufferFileSizeLimitBytes: null,
bufferFileShared: false,
retainedBufferFileCountLimit: 31,
logEventLimitBytes: null,
logEventsInBatchLimit: 1000,
batchSizeLimitBytes: null,
period: period,
flushOnClose: flushOnClose,
textFormatter: new NormalTextFormatter(),
batchFormatter: new ArrayBatchFormatter(),
httpClient: new JsonHttpClient(webServerFixture.CreateClient()));

// Act
foreach (var logEvent in logEvents)
{
sink.Emit(logEvent);
}

sink.Dispose();

// Assert
webServerFixture.GetAllEvents(testId).Length.ShouldBe(logEvents.Length);
}

[Fact]
public void IgnoreSendingStoredLogEventsGivenNoFlushOnClose()
{
// Arrange
var testId = $"IgnoreSendingStoredLogEventsGivenNoFlushOnClose_{Guid.NewGuid()}";

// Create 10 log events
var logEvents = Enumerable
.Range(1, 10)
.Select(number => Some.LogEvent("Event {number}", number))
.ToArray();

var period = TimeSpan.FromSeconds(5);
var flushOnClose = false;

var sink = new TimeRolledDurableHttpSink(
requestUri: webServerFixture.RequestUri(testId),
bufferBaseFileName: Path.Combine("logs", testId),
bufferRollingInterval: BufferRollingInterval.Day,
bufferFileSizeLimitBytes: null,
bufferFileShared: false,
retainedBufferFileCountLimit: 31,
logEventLimitBytes: null,
logEventsInBatchLimit: 1000,
batchSizeLimitBytes: null,
period: period,
flushOnClose: flushOnClose,
textFormatter: new NormalTextFormatter(),
batchFormatter: new ArrayBatchFormatter(),
httpClient: new JsonHttpClient(webServerFixture.CreateClient()));

// Act
foreach (var logEvent in logEvents)
{
sink.Emit(logEvent);
}

sink.Dispose();

// Assert
webServerFixture.GetAllEvents(testId).Length.ShouldBe(0);
}
}

0 comments on commit ec88cce

Please sign in to comment.