serilog / serilog-sinks-periodicbatching

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

EagerlyEmitFirstEvent is ignored #70

Closed ArieGato closed 3 months ago

ArieGato commented 3 months ago

After upgrading to 4.0.0 it appears that EagerlyEmitFirstEvent is ignored.

This unit test fails. Increasing the Task.Delay to 2100 will make this test succeed.

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

        var options = new PeriodicBatchingSinkOptions
        {
            Period = TimeSpan.FromSeconds(2),
            EagerlyEmitFirstEvent = true,
            BatchSizeLimit = 10,
            QueueLimit = 1000
        };
        var pbs = new PeriodicBatchingSink(bs, options);
        var evt = Some.InformationEvent();
        pbs.Emit(evt);

        await Task.Delay(1900);
        Assert.True(eventEmitted);

        pbs.Dispose();
    }
nblumhardt commented 3 months ago

Thanks for the report! Looks like a simple Boolean condition screw-up.

I've pushed your test up in #71, let me know if it wasn't your intention to contribute this. Many thanks!

ArieGato commented 3 months ago

It was, and my next step would be to have a go at it. But you beat me to it.

ArieGato commented 3 months ago

Great, thnx for the rapiid response.