fix: enforce logger entry budget across batches

This commit is contained in:
MiMoCode
2026-07-10 18:30:46 +08:00
parent c4a985e9ca
commit 044bed77e6
2 changed files with 36 additions and 0 deletions
+21
View File
@@ -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))