feat: snapshot retained client reconciliation state
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package spool
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
rvboxv1 "github.com/rvbox/rvbox/gen/go/rvbox/v1"
|
||||
)
|
||||
|
||||
func TestReconcileSnapshotRetainedAndTombstoned_HP_SES_09(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
store := openTestStore(t, ctx, filepath.Join(t.TempDir(), "spool"), DefaultTombstoneLimit)
|
||||
issue := testUUID(t, "019c46f1-1d02-7000-8000-000000000081")
|
||||
command := testCommand(issue, []byte("reconcile"))
|
||||
if _, err := store.AcceptCommand(ctx, command, time.Now().UTC()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := store.AppendEvent(ctx, issue, EventInput{Kind: 3, Compression: 1, Payload: []byte("running"), CreatedAt: time.Now().UTC()}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := store.AssignSendWindow(ctx, issue, 1, 1<<20); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
snapshot, err := store.ReconcileSnapshot(ctx)
|
||||
if err != nil || len(snapshot.RetainedCommands) != 1 {
|
||||
t.Fatalf("retained snapshot = %#v, %v", snapshot, err)
|
||||
}
|
||||
retained := snapshot.RetainedCommands[0]
|
||||
if retained.GetIssueUuid() != issue.String() || retained.GetLastClientEventSeq() != 1 || retained.GetTombstoned() || retained.GetLifecycle() != rvboxv1.CommandLifecycle_COMMAND_QUEUED {
|
||||
t.Fatalf("retained command = %#v", retained)
|
||||
}
|
||||
if err := store.Ack(ctx, issue, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.MarkTerminal(ctx, issue, uint32(rvboxv1.CommandLifecycle_COMMAND_SUCCEEDED)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.CleanupTerminal(ctx, issue, time.Now().UTC()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
snapshot, err = store.ReconcileSnapshot(ctx)
|
||||
if err != nil || len(snapshot.RetainedCommands) != 1 {
|
||||
t.Fatalf("tombstone snapshot = %#v, %v", snapshot, err)
|
||||
}
|
||||
tombstone := snapshot.RetainedCommands[0]
|
||||
if !tombstone.GetTombstoned() || tombstone.GetLifecycle() != rvboxv1.CommandLifecycle_COMMAND_SUCCEEDED || tombstone.GetCommandRevision() != 1 || tombstone.GetLastClientEventSeq() != 0 {
|
||||
t.Fatalf("tombstone command = %#v", tombstone)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user