-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent durable sink from posting empty batches
Prevent durable HTTP sink from posting HTTP messages without any log events. Closes #32
- Loading branch information
1 parent
20139ce
commit 959d918
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
test/Serilog.Sinks.HttpTests/Sinks/Http/Private/Sinks/HttpSinkTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Moq; | ||
using Serilog.Sinks.Http.BatchFormatters; | ||
using Serilog.Sinks.Http.TextFormatters; | ||
using Xunit; | ||
|
||
namespace Serilog.Sinks.Http.Private.Sinks | ||
{ | ||
public class HttpSinkTest | ||
{ | ||
[Fact] | ||
public async Task NoNetworkTrafficWithoutLogEvents() | ||
{ | ||
// Arrange | ||
var httpClient = new Mock<IHttpClient>(); | ||
|
||
// ReSharper disable once UnusedVariable | ||
var httpSink = new HttpSink( | ||
"api/events", | ||
1000, | ||
TimeSpan.FromSeconds(2), | ||
new NormalRenderedTextFormatter(), | ||
new DefaultBatchFormatter(), | ||
httpClient.Object); | ||
|
||
// Act | ||
await Task.Delay(TimeSpan.FromMinutes(3)); | ||
|
||
// Assert | ||
httpClient.Verify( | ||
mock => mock.PostAsync(It.IsAny<string>(), It.IsAny<HttpContent>()), | ||
Times.Never); | ||
} | ||
} | ||
} |