Skip to content

Commit

Permalink
Merge pull request #72 from serilog/dev
Browse files Browse the repository at this point in the history
4.0.1 Release
  • Loading branch information
nblumhardt authored Mar 15, 2024
2 parents b3821e5 + d139ae5 commit 87a2ac3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>Buffer batches of log events to be flushed asynchronously.</Description>
<VersionPrefix>4.0.0</VersionPrefix>
<VersionPrefix>4.0.1</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net462</TargetFrameworks>
<TargetFrameworks>$(TargetFrameworks);netstandard2.0;net6.0</TargetFrameworks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async Task LoopAsync()
{
_currentBatch.Enqueue(next);
}
} while ((_currentBatch.Count < _batchSizeLimit || _currentBatch.Count > 0 && isEagerBatch) &&
} while ((_currentBatch.Count < _batchSizeLimit && !isEagerBatch || _currentBatch.Count == 0) &&
!_shutdownSignal.IsCancellationRequested &&
await TryWaitToReadAsync(_queue.Reader, fillBatch, _shutdownSignal.Token).ConfigureAwait(false));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,44 @@ public void ExecutionContextDoesNotFlowToBatchedSink()
pbs.Emit(evt);
pbs.Dispose();

Assert.Equal(default(int), observed);
Assert.Equal(default, observed);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task EagerlyEmitFirstEventCausesQuickInitialBatch(bool eagerlyEmit)
{
long batchesEmitted = 0;
var bs = new CallbackBatchedSink(_ =>
{
// ReSharper disable once AccessToModifiedClosure
Interlocked.Increment(ref batchesEmitted);
return Task.CompletedTask;
});

var options = new PeriodicBatchingSinkOptions
{
Period = TimeSpan.FromSeconds(2),
EagerlyEmitFirstEvent = eagerlyEmit,
BatchSizeLimit = 10,
QueueLimit = 1000
};

var pbs = new PeriodicBatchingSink(bs, options);

var evt = Some.InformationEvent();
pbs.Emit(evt);

await Task.Delay(1900);
Assert.Equal(eagerlyEmit ? 1L : 0, Interlocked.Read(ref batchesEmitted));

#if FEATURE_ASYNCDISPOSABLE
await pbs.DisposeAsync();
#else
pbs.Dispose();
#endif

Assert.Equal(1L, Interlocked.Read(ref batchesEmitted));
}
}

0 comments on commit 87a2ac3

Please sign in to comment.