fix: preserve logger byte reservations

This commit is contained in:
MiMoCode
2026-07-10 18:33:27 +08:00
parent 044bed77e6
commit 8eaab5ccfb
2 changed files with 46 additions and 11 deletions
+26
View File
@@ -267,6 +267,32 @@ func TestQueueStopBeforeStartReleasesBudget(t *testing.T) {
}
}
func TestQueueReleasesSubmittedSizeAfterEntryMutation(t *testing.T) {
for _, tc := range []struct {
name string
mutate func(*logger.LogEntry)
}{
{name: "smaller", mutate: func(entry *logger.LogEntry) { entry.RequestBody = nil }},
{name: "larger", mutate: func(entry *logger.LogEntry) { entry.RequestBody = []byte("much larger body") }},
} {
t.Run(tc.name, func(t *testing.T) {
entry := &logger.LogEntry{RequestID: "queued", RequestBody: []byte("body")}
q := logger.NewQueue(nil, 2, 2, 1, time.Hour, logger.EstimatedBytes(entry))
q.Submit(entry)
tc.mutate(entry)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
if err := q.Stop(ctx); err != nil {
t.Fatalf("Stop: %v", err)
}
if stats := q.Stats(); stats.Bytes != 0 || stats.Failed != 1 {
t.Fatalf("stats=%+v", stats)
}
})
}
}
func TestQueueCanceledStopEventuallyReleasesAllBudget(t *testing.T) {
entry := &logger.LogEntry{RequestID: "queued"}
q := logger.NewQueue(nil, 32, 32, 1, time.Hour, 32*logger.EstimatedBytes(entry))