Test that a notice worker never prunes with an older snapshot (#491)
Astra's re-check of the R1 P2 fix called it partly resolved: the order was fixed but the deterministic test it asked for was missing. This holds n.mu while a worker waits on it, moves the home map on and creates a new peer, and checks the worker keeps that peer once it has the lock. Watched to fail with the snapshot read before the lock.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+56
−0
internal/edge/burst_notice_test.go+56 −0
CI passed — run details
diff --git a/internal/edge/burst_notice_test.go b/internal/edge/burst_notice_test.go| index 452b48524..ad07e8706 100644 |
| --- a/internal/edge/burst_notice_test.go |
| +++ b/internal/edge/burst_notice_test.go |
| @@ -602,6 +602,62 @@ func TestBurstNoticeDepartedPeerStopsAtDispatch(t *testing.T) { |
| waitFor(t, 5*time.Second, "betty's worker gone", func() bool { return peers() == 1 }) |
| } |
| +// Astra R1 P2: a worker checking its peer never prunes with a home map |
| +// older than the one a newer peer was created from. The worker waits on |
| +// n.mu while sendBurstNotices, holding it, sees betty arrive in a newer |
| +// snapshot and creates her peer; once the worker has the lock, betty stays. |
| +// With the snapshot read before the lock the worker would prune her. |
| +func TestBurstPeerCurrentNeverPrunesWithAnOlderSnapshot(t *testing.T) { |
| + file := func(box, eip, host string) edgesFileView { |
| + return edgesFileView{V: 1, Box: box, EIP: eip, BurstNotices: true, Hosts: map[string]edgesHostView{host: {Role: "home"}}} |
| + } |
| + annie, betty, carol := file("annie", "192.0.2.11", "shop.example.com"), file("betty", "192.0.2.12", "blog.example.com"), file("carol", "192.0.2.13", "docs.example.com") |
| + m := &homeMap{snap: &homeSnapshot{read: true, files: map[string]edgesFileView{ |
| + "control/edges/annie.json": annie, "control/edges/carol.json": carol, |
| + }}} |
| + e := &Edge{box: "annie"} |
| + e.homes.Store(m) |
| + n := newBurstNotices() |
| + peer := func(box string) *burstPeer { |
| + return &burstPeer{box: box, q: make(chan burstNotice, 1), stop: make(chan struct{})} |
| + } |
| + carolPeer := peer("carol") |
| + n.peers["carol"] = carolPeer |
| + |
| + n.mu.Lock() |
| + done := make(chan bool, 1) |
| + go func() { done <- e.burstPeerCurrent(n, carolPeer) }() |
| + // Long enough for the worker to reach the lock (and, read in the old |
| + // order, the snapshot without betty). |
| + time.Sleep(200 * time.Millisecond) |
| + m.mu.Lock() |
| + m.snap = &homeSnapshot{read: true, files: map[string]edgesFileView{ |
| + "control/edges/annie.json": annie, "control/edges/betty.json": betty, "control/edges/carol.json": carol, |
| + }} |
| + m.mu.Unlock() |
| + targets := n.targetsLocked(m.snapshot(), e.box, false) |
| + if len(targets) != 2 { |
| + t.Fatalf("targets %+v, want betty and carol", targets) |
| + } |
| + bettyPeer := peer("betty") |
| + n.peers["betty"] = bettyPeer |
| + n.mu.Unlock() |
| + |
| + if !<-done { |
| + t.Fatal("carol, still a peer, was reported gone") |
| + } |
| + n.mu.Lock() |
| + defer n.mu.Unlock() |
| + if n.peers["betty"] != bettyPeer { |
| + t.Fatal("betty's new peer was pruned with the older snapshot") |
| + } |
| + select { |
| + case <-bettyPeer.stop: |
| + t.Fatal("betty's worker was stopped") |
| + default: |
| + } |
| +} |
| + |
| // R3-2: the budget is taken at dispatch, over any 60 s and not per |
| // calendar minute, and a notice that cannot be sent within 10 s of its |
| // trip is dropped and counted. |