fix: preserve logger byte reservations
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user