carlos / platform Public

Merge main into group-observation-carry

claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 3e9f97daabafdd3e693ade706f8b829a074560e0 parent 94788d1parent 293881a
2 files changed, +52 −32
  • internal/host/interactive_test.go +22 −1
  • internal/lease/release_snapshot_test.go +30 −31

CI passed — run details

diff --git a/internal/host/interactive_test.go b/internal/host/interactive_test.go
index c0c77a37c..4b1042433 100644
--- a/internal/host/interactive_test.go
+++ b/internal/host/interactive_test.go
@@ -492,6 +492,23 @@ func (d *ixDoor) wantStatus(t *testing.T, state string) {
}
}
+// wantEndAfterStatus is wantEnd where another connection's Status frames
+// may come first on the shared channel; it skips those, nothing else.
+func (d *ixDoor) wantEndAfterStatus(t *testing.T) interactive.End {
+ t.Helper()
+ for {
+ f := d.next(t)
+ if f.kind == interactive.KindStatus {
+ continue
+ }
+ var e interactive.End
+ if f.kind != interactive.KindEnd || json.Unmarshal(f.payload, &e) != nil {
+ t.Fatalf("frame %q %s, want an End", f.kind, f.payload)
+ }
+ return e
+ }
+}
+
func (d *ixDoor) wantEnd(t *testing.T) interactive.End {
t.Helper()
f := d.next(t)
@@ -2099,7 +2116,11 @@ func TestInteractiveWorkerReaderGivesUpWhenReplacedDuringOpen(t *testing.T) {
waitFor(t, "the replacement", func() bool { return s.ctx.Err() != nil })
}
wd.session()
- if e := wd.door.wantEnd(t); e.Reason != interactive.EndReplaced {
+ // The door's frames come from both connections on one channel. The old
+ // session sends its End before the new one dials, but each connection
+ // is read on its own goroutine, so the new session's Status can be
+ // queued first (#897: frame 's' {"state":"starting"}, want an End).
+ if e := wd.door.wantEndAfterStatus(t); e.Reason != interactive.EndReplaced {
t.Fatalf("the old session's end %+v, want replaced", e)
}
waitFor(t, "the new session to start", func() bool { return len(wd.launch.calls()) == 1 })
diff --git a/internal/lease/release_snapshot_test.go b/internal/lease/release_snapshot_test.go
index 3b2cafd61..7af076170 100644
--- a/internal/lease/release_snapshot_test.go
+++ b/internal/lease/release_snapshot_test.go
@@ -27,22 +27,32 @@ import (
// and no L0 tail. An idle sleep's release writes none.
// countingReplica is a replica client that counts the LTX files opened
-// (a restore's reads, one GET each on S3) and records the levels written,
-// and can refuse snapshot writes.
+// (a restore's reads, one GET each on S3), records the snapshots a release
+// writes (releaseCall), and can refuse snapshot writes.
// drainSnapshotOnly marks the context of the drain release's own snapshot,
// so a refusing fake can refuse that snapshot and no other.
type drainSnapshotOnly struct{}
+// releaseCall marks the context a test passes to a release (Finish,
+// FinishSnapshot, ReleaseMarker), so the fake can tell the release's own
+// snapshots from the store monitor's. litestream's snapshot monitor writes
+// the store's first snapshot about a second after a fresh replica opens,
+// on the store's context; on a loaded CI worker that landed inside a
+// release and was counted as the release's (#897).
+type releaseCall struct{}
+
type countingReplica struct {
litestream.ReplicaClient
mu sync.Mutex
opens int
- writes []int
snapshotTXID ltx.TXID
failSnapshot bool
// refuseEarly refuses a snapshot without reading any of it, as an
// upload that fails before it consumes the body.
refuseEarly bool
+ // releaseSnaps are the TXIDs of the snapshots written on a releaseCall
+ // context, in order.
+ releaseSnaps []ltx.TXID
}
func (c *countingReplica) OpenLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, offset, size int64) (io.ReadCloser, error) {
@@ -54,7 +64,6 @@ func (c *countingReplica) OpenLTXFile(ctx context.Context, level int, minTXID, m
func (c *countingReplica) WriteLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, r io.Reader) (*ltx.FileInfo, error) {
c.mu.Lock()
- c.writes = append(c.writes, level)
fail := c.failSnapshot && level == litestream.SnapshotLevel
// Only the drain's own snapshot is refused: the test marks its context
// (drainSnapshotOnly). The store monitor's snapshots run on the store's
@@ -64,6 +73,9 @@ func (c *countingReplica) WriteLTXFile(ctx context.Context, level int, minTXID,
early := c.refuseEarly && level == litestream.SnapshotLevel && ctx.Value(drainSnapshotOnly{}) != nil
if level == litestream.SnapshotLevel {
c.snapshotTXID = maxTXID
+ if ctx.Value(releaseCall{}) != nil {
+ c.releaseSnaps = append(c.releaseSnaps, maxTXID)
+ }
}
c.mu.Unlock()
if early {
@@ -76,22 +88,12 @@ func (c *countingReplica) WriteLTXFile(ctx context.Context, level int, minTXID,
return c.ReplicaClient.WriteLTXFile(ctx, level, minTXID, maxTXID, r)
}
-func (c *countingReplica) mark() int {
- c.mu.Lock()
- defer c.mu.Unlock()
- return len(c.writes)
-}
-
-func (c *countingReplica) snapshotsSince(n int) int {
+// releaseSnapshots are the snapshots written by the releases a test marked
+// with releaseCall, at their TXIDs.
+func (c *countingReplica) releaseSnapshots() []ltx.TXID {
c.mu.Lock()
defer c.mu.Unlock()
- k := 0
- for _, l := range c.writes[n:] {
- if l == litestream.SnapshotLevel {
- k++
- }
- }
- return k
+ return append([]ltx.TXID(nil), c.releaseSnaps...)
}
func (c *countingReplica) openCount() int {
@@ -156,12 +158,12 @@ func TestDrainReleaseSnapshotRestoresFromOneFile(t *testing.T) {
dir := t.TempDir()
rc := &countingReplica{ReplicaClient: lsfile.NewReplicaClient(dir)}
r, path := manyL0(t, fx, "instances/h", rc, 200)
- before := rc.mark()
- txid, snapErr, err := r.FinishSnapshot(ctx)
+ rctx := context.WithValue(ctx, releaseCall{}, true)
+ txid, snapErr, err := r.FinishSnapshot(rctx)
if err != nil || snapErr != nil || txid == 0 {
t.Fatalf("FinishSnapshot: txid %d, snapshot %v, %v", txid, snapErr, err)
}
- if err := r.ReleaseMarker(ctx, hafresh.Marker{V: 1, Clean: true}); err != nil {
+ if err := r.ReleaseMarker(rctx, hafresh.Marker{V: 1, Clean: true}); err != nil {
t.Fatal(err)
}
if m := lockView(t, fx, "instances/h").Lock.Release; m == nil || !m.Clean || m.TXID != txid {
@@ -174,11 +176,8 @@ func TestDrainReleaseSnapshotRestoresFromOneFile(t *testing.T) {
if got, want := dbRows(t, out), dbRows(t, path); got != want {
t.Fatalf("restored %q, want %q", got, want)
}
- if k := rc.snapshotsSince(before); k != 1 {
- t.Fatalf("%d snapshots written by the drain's release, want 1", k)
- }
- if uint64(rc.snapshotTXID) != txid {
- t.Fatalf("snapshot at txid %d, final txid %d", rc.snapshotTXID, txid)
+ if snaps := rc.releaseSnapshots(); len(snaps) != 1 || uint64(snaps[0]) != txid {
+ t.Fatalf("snapshots written by the drain's release at %v, want one at the final txid %d", snaps, txid)
}
}
@@ -188,15 +187,15 @@ func TestSleepReleaseWritesNoSnapshot(t *testing.T) {
fx := leasetest.NewLockFixture(t)
rc := &countingReplica{ReplicaClient: lsfile.NewReplicaClient(t.TempDir())}
r, _ := manyL0(t, fx, "instances/h", rc, 5)
- before := rc.mark()
- if _, err := r.Finish(ctx); err != nil {
+ rctx := context.WithValue(ctx, releaseCall{}, true)
+ if _, err := r.Finish(rctx); err != nil {
t.Fatal(err)
}
- if err := r.ReleaseMarker(ctx, hafresh.Marker{V: 1, Clean: true}); err != nil {
+ if err := r.ReleaseMarker(rctx, hafresh.Marker{V: 1, Clean: true}); err != nil {
t.Fatal(err)
}
- if k := rc.snapshotsSince(before); k != 0 {
- t.Fatalf("a sleep's release wrote %d snapshots", k)
+ if snaps := rc.releaseSnapshots(); len(snaps) != 0 {
+ t.Fatalf("a sleep's release wrote %d snapshots", len(snaps))
}
}