serilog / serilog-sinks-periodicbatching

Infrastructure for Serilog sinks that process events in batches.
Apache License 2.0
70 stars 29 forks source link

Fix observance of `options.EagerlyEmitFirstEvent` #71

Closed nblumhardt closed 3 months ago

nblumhardt commented 3 months ago

Fixes #70

ArieGato commented 3 months ago

I would also add a test case to test for EagerlyEmitFirstEvent = false

something like this (untested):

    [Fact]
    public async Task WhenEagerlyEmitFirstEventIsFalseItShouldNotWriteToBatchImmediately()
    {
        var eventEmitted = false;
        var bs = new CallbackBatchedSink(_ =>
        {
            eventEmitted = true;
            return Task.CompletedTask;
        });

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

#if FEATURE_ASYNCDISPOSABLE
        await
#endif
        using var pbs = new PeriodicBatchingSink(bs, options);

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

        await Task.Delay(100);
        Assert.False(eventEmitted);
    }
nblumhardt commented 3 months ago

Changed to a theory so we can test the true/false cases together 👍