init
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package spool
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"browser.local/run/protocol"
|
||||
)
|
||||
|
||||
func TestLogSpoolAckIsIndependentFromArtifactBacklog(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
logSpool, err := NewLogSpool(root)
|
||||
if err != nil {
|
||||
t.Fatalf("new log spool: %v", err)
|
||||
}
|
||||
artifactQueue, err := NewArtifactQueue(root)
|
||||
if err != nil {
|
||||
t.Fatalf("new artifact queue: %v", err)
|
||||
}
|
||||
|
||||
if err := logSpool.Enqueue(validSpoolLogBatch(1, 1)); err != nil {
|
||||
t.Fatalf("enqueue log: %v", err)
|
||||
}
|
||||
for i := 0; i < 3; i++ {
|
||||
if err := artifactQueue.Enqueue(validQueuedArtifactChunk(i)); err != nil {
|
||||
t.Fatalf("enqueue artifact chunk %d: %v", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := logSpool.Ack(protocol.LogBatchIngestResponse{Accepted: true, LogStreamID: "log-1", AcceptedFrom: 1, AcceptedTo: 1}); err != nil {
|
||||
t.Fatalf("ack log batch: %v", err)
|
||||
}
|
||||
logs, err := logSpool.Pending()
|
||||
if err != nil {
|
||||
t.Fatalf("pending logs: %v", err)
|
||||
}
|
||||
if len(logs) != 0 {
|
||||
t.Fatalf("expected log batch removed despite artifact backlog, got %+v", logs)
|
||||
}
|
||||
chunks, err := artifactQueue.Pending()
|
||||
if err != nil {
|
||||
t.Fatalf("pending artifacts: %v", err)
|
||||
}
|
||||
if len(chunks) != 3 {
|
||||
t.Fatalf("artifact backlog should remain independent, got %+v", chunks)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArtifactAckIsIndependentFromLogBacklog(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
logSpool, err := NewLogSpool(root)
|
||||
if err != nil {
|
||||
t.Fatalf("new log spool: %v", err)
|
||||
}
|
||||
artifactQueue, err := NewArtifactQueue(root)
|
||||
if err != nil {
|
||||
t.Fatalf("new artifact queue: %v", err)
|
||||
}
|
||||
|
||||
for _, batch := range []protocol.LogBatchIngestRequest{validSpoolLogBatch(1, 1), validSpoolLogBatch(2, 2)} {
|
||||
if err := logSpool.Enqueue(batch); err != nil {
|
||||
t.Fatalf("enqueue log batch: %v", err)
|
||||
}
|
||||
}
|
||||
if err := artifactQueue.Enqueue(validQueuedArtifactChunk(0)); err != nil {
|
||||
t.Fatalf("enqueue artifact chunk: %v", err)
|
||||
}
|
||||
|
||||
if err := artifactQueue.Ack(protocol.ArtifactChunkUploadResponse{Accepted: true, TransferID: "transfer-1", ArtifactID: "artifact-1", ChunkIndex: 0}); err != nil {
|
||||
t.Fatalf("ack artifact chunk: %v", err)
|
||||
}
|
||||
chunks, err := artifactQueue.Pending()
|
||||
if err != nil {
|
||||
t.Fatalf("pending artifacts: %v", err)
|
||||
}
|
||||
if len(chunks) != 0 {
|
||||
t.Fatalf("expected artifact chunk removed despite log backlog, got %+v", chunks)
|
||||
}
|
||||
logs, err := logSpool.Pending()
|
||||
if err != nil {
|
||||
t.Fatalf("pending logs: %v", err)
|
||||
}
|
||||
if len(logs) != 2 {
|
||||
t.Fatalf("log backlog should remain independent, got %+v", logs)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user