carlos / platform Public

host: tests for the cut's row hold and the stopped database's local position

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev cb9928da609b1b0a81ba5dc99db12916495e8e15 parent 96ee1c3
1 file changed, +57 −0
  • internal/host/movescut_test.go +57 −0
diff --git a/internal/host/movescut_test.go b/internal/host/movescut_test.go
index 1b5adc465..d6acdb7a7 100644
--- a/internal/host/movescut_test.go
+++ b/internal/host/movescut_test.go
@@ -919,3 +919,60 @@ func TestSealRefusesAnObjectWithoutAUsableVersion(t *testing.T) {
}
}
}
+
+// holdMoving holds the row moving under the op, once, with the
+// stage-requested marker touched for a write that landed; a row already so
+// held is left alone, and a row another op holds is refused.
+func TestHoldMovingIsConditional(t *testing.T) {
+ reg, err := registry.Open(filepath.Join(t.TempDir(), "registry.db"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer reg.Close()
+ if err := reg.Upsert(registry.Route{Host: p1Host, Kind: "instance", App: "app", Account: "bab", Status: "ready", Provisioned: true}); err != nil {
+ t.Fatal(err)
+ }
+ var written []string
+ hold := holdMoving(reg, func(host string) { written = append(written, host) })
+ if err := hold(p1Host, p1ID); err != nil {
+ t.Fatal(err)
+ }
+ if err := hold(p1Host, p1ID); err != nil {
+ t.Fatalf("a second hold under the same op: %v", err)
+ }
+ rt, err := reg.Get(p1Host)
+ if err != nil || rt.Status != "moving" || rt.HoldOp != p1ID || len(written) != 1 {
+ t.Fatalf("row %+v, %v; marker touched %d times", rt, err, len(written))
+ }
+ if err := hold(p1Host, p1ID2); err == nil {
+ t.Fatal("another op's hold was taken over")
+ }
+ if rt, _ := reg.Get(p1Host); rt.HoldOp != p1ID {
+ t.Fatalf("the hold moved to %s", rt.HoldOp)
+ }
+ if err := hold("absent.example.com", p1ID); err == nil {
+ t.Fatal("a missing row was held")
+ }
+}
+
+// localLTXPosition reads the newest level-0 file of the activator's meta
+// directory (lease.Held's SetMetaPath); no directory is position 0.
+func TestLocalLTXPosition(t *testing.T) {
+ dir := t.TempDir()
+ db := filepath.Join(dir, p1Host+".db")
+ if n, err := localLTXPosition(db); err != nil || n != 0 {
+ t.Fatalf("no meta directory: %d, %v", n, err)
+ }
+ l0 := filepath.Join(dir, ".activator-"+p1Host+".db-litestream", "ltx", "0")
+ if err := os.MkdirAll(l0, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ for _, name := range []string{"0000000000000001-0000000000000005.ltx", "0000000000000006-000000000000000a.ltx", "junk", "0000000000000003-0000000000000004.ltx"} {
+ if err := os.WriteFile(filepath.Join(l0, name), nil, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if n, err := localLTXPosition(db); err != nil || n != 10 {
+ t.Fatalf("position %d, %v; want 10", n, err)
+ }
+}