oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package thintest
2
3import "amadan.net/oficina/equipo/internal/wire"
4
5// Whole-branch fix 1 helpers.
6
7// sendHeld sends a durable frame and then a lease round trip (frames are
8// applied in order), and reports whether the frame was acked meanwhile.
9// Other frames that arrive are held as send holds them.
10func (p *peer) sendHeld(id, kind string, body any) (acked bool) {
11 p.t.Helper()
12 if err := p.fr.Send(p.r.ctx, id, kind, body); err != nil {
13 p.t.Fatal(err)
14 }
15 lease := p.id("p-lease")
16 if err := p.fr.Send(p.r.ctx, lease, wire.FrameLease, wire.LeaseCheck{Generation: p.fr.Welcome.Generation}); err != nil {
17 p.t.Fatal(err)
18 }
19 for {
20 f, body, err := p.fr.Next(p.r.ctx)
21 if err != nil {
22 p.t.Fatalf("waiting for the lease after %s: %v", id, err)
23 }
24 if a, ok := body.(*wire.Ack); ok {
25 switch a.ID {
26 case id:
27 acked = true
28 case lease:
29 return acked
30 }
31 continue
32 }
33 p.held = append(p.held, heldFrame{f, body, p.fr.Received[len(p.fr.Received)-1]})
34 }
35}
36
37// sendAs sends a durable frame under id (a replay from the runner's
38// outbox) and waits for its ack.
39func (p *peer) sendAs(id, kind string, body any) {
40 p.t.Helper()
41 if acked := p.sendHeld(id, kind, body); !acked {
42 p.t.Fatalf("%s %s not acked", kind, id)
43 }
44}
45