init
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package spool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"browser.local/run/protocol"
|
||||
)
|
||||
|
||||
type fakeLogBatchClient struct {
|
||||
accepted bool
|
||||
}
|
||||
|
||||
func (client fakeLogBatchClient) IngestLogBatch(_ context.Context, batch protocol.LogBatchIngestRequest) (protocol.LogBatchIngestResponse, error) {
|
||||
return protocol.LogBatchIngestResponse{Accepted: client.accepted, LogStreamID: batch.LogStreamID, AcceptedFrom: batch.FirstSeq, AcceptedTo: batch.LastSeq}, nil
|
||||
}
|
||||
|
||||
func TestLogSpoolFlushRetainsRejectedBatchForRetry(t *testing.T) {
|
||||
spool, err := NewLogSpool(t.TempDir())
|
||||
if err != nil {
|
||||
t.Fatalf("new spool: %v", err)
|
||||
}
|
||||
if err := spool.Enqueue(validSpoolLogBatch(1, 1)); err != nil {
|
||||
t.Fatalf("enqueue: %v", err)
|
||||
}
|
||||
if _, err := spool.Flush(context.Background(), fakeLogBatchClient{accepted: false}); err == nil {
|
||||
t.Fatal("expected rejected flush")
|
||||
}
|
||||
pending, err := spool.Pending()
|
||||
if err != nil || len(pending) != 1 {
|
||||
t.Fatalf("expected batch retained after rejection, pending=%+v err=%v", pending, err)
|
||||
}
|
||||
if count, err := spool.Flush(context.Background(), fakeLogBatchClient{accepted: true}); err != nil || count != 1 {
|
||||
t.Fatalf("expected retry success, count=%d err=%v", count, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user