fix: snapshot queued log entries
This commit is contained in:
@@ -314,6 +314,50 @@ func TestQueueReleasesSubmittedSizeAfterEntryMutation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueueSubmitOwnsEntrySnapshot(t *testing.T) {
|
||||
prepareStarted := make(chan struct{})
|
||||
releasePrepare := make(chan struct{})
|
||||
batch := &fakeBatch{}
|
||||
backend := newQueueBackend(func(context.Context, string) (logger.Batch, error) {
|
||||
close(prepareStarted)
|
||||
<-releasePrepare
|
||||
return batch, nil
|
||||
})
|
||||
entry := &logger.LogEntry{
|
||||
RequestID: "original-id",
|
||||
RequestHeaders: []byte("original-request-headers"),
|
||||
RequestBody: []byte("original-request-body"),
|
||||
ResponseHeaders: []byte("original-response-headers"),
|
||||
ResponseBody: []byte("original-response-body"),
|
||||
}
|
||||
q := logger.NewQueueWithBackend(backend, 1, 1, 1, time.Hour)
|
||||
q.Start(context.Background())
|
||||
q.Submit(entry)
|
||||
<-prepareStarted
|
||||
|
||||
entry.RequestID = "mutated-id"
|
||||
entry.RequestHeaders[0] = 'X'
|
||||
entry.RequestBody[0] = 'X'
|
||||
entry.ResponseHeaders[0] = 'X'
|
||||
entry.ResponseBody[0] = 'X'
|
||||
close(releasePrepare)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
if err := q.Stop(ctx); err != nil {
|
||||
t.Fatalf("Stop: %v", err)
|
||||
}
|
||||
if len(batch.rows) != 1 {
|
||||
t.Fatalf("written rows=%d want 1", len(batch.rows))
|
||||
}
|
||||
row := batch.rows[0]
|
||||
if row[0] != "original-id" ||
|
||||
row[5] != "original-request-headers" || row[6] != "original-request-body" ||
|
||||
row[9] != "original-response-headers" || row[10] != "original-response-body" {
|
||||
t.Fatalf("queued entry changed after Submit: %#v", row)
|
||||
}
|
||||
}
|
||||
|
||||
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