fix(go): batch durable spool replay

This commit is contained in:
lingniu
2026-07-02 13:29:49 +08:00
parent bc9025d566
commit 75e7c3fbe5
3 changed files with 48 additions and 9 deletions

View File

@@ -118,6 +118,26 @@ func TestDurableSinkReplayLoopTickUsesUncancelledContext(t *testing.T) {
}
}
func TestDurableSinkReplayLoopTickRespectsBatchSize(t *testing.T) {
dir := t.TempDir()
env := durableTestEnvelope()
for index := 0; index < 5; index++ {
writeDurableRecord(t, filepath.Join(dir, "000"+string(rune('1'+index))+"-raw.json"), durableRecord{Kind: "raw", Envelope: env})
}
delegate := &contextCheckingReplaySink{}
sink := NewDurableSink(delegate, DurableConfig{Directory: dir, ReplayBatchSize: 2})
if err := sink.replayOnceFromLoop(context.Background()); err != nil {
t.Fatalf("replayOnceFromLoop() error = %v", err)
}
if delegate.rawCalls != 2 {
t.Fatalf("raw calls = %d, want 2", delegate.rawCalls)
}
if files := spoolFiles(t, dir); len(files) != 3 {
t.Fatalf("spool files after replay = %d, want 3: %#v", len(files), files)
}
}
func durableTestEnvelope() envelope.FrameEnvelope {
return envelope.FrameEnvelope{
Protocol: envelope.ProtocolJT808,