fix: enforce logger entry budget across batches
This commit is contained in:
@@ -231,6 +231,27 @@ func TestQueueByteBudgetReleasedAfterFinalDiscard(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueueEntryBudgetIncludesWorkerBatch(t *testing.T) {
|
||||
q := logger.NewQueue(nil, 1, 2, 1, time.Hour)
|
||||
q.Submit(&logger.LogEntry{RequestID: "batched"})
|
||||
q.Start(context.Background())
|
||||
|
||||
deadline := time.Now().Add(time.Second)
|
||||
for q.Stats().Enqueued == 1 && time.Now().Before(deadline) {
|
||||
q.Submit(&logger.LogEntry{RequestID: "queued"})
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
if stats := q.Stats(); stats.Enqueued != 1 {
|
||||
t.Fatalf("stats=%+v; entry budget allowed channel plus worker batch", stats)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
if err := q.Stop(ctx); err != nil {
|
||||
t.Fatalf("Stop: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueueStopBeforeStartReleasesBudget(t *testing.T) {
|
||||
entry := &logger.LogEntry{RequestID: "queued"}
|
||||
q := logger.NewQueue(nil, 2, 2, 1, time.Hour, logger.EstimatedBytes(entry))
|
||||
|
||||
Reference in New Issue
Block a user