Pipeline main.8 failed TestBridgeSaysOneHeadMovedPerMove and TestBridgePerformsWhatIsOwedOnce on
shanks; both fail the same way at 403fb306, before the catalog client change, under load.
- The bridge read every head again, start true, whenever the registrations' first view said its
values after the start had begun, so a head moved just after the start was said as a start.
Only a registration adding a watched branch is adopted now (Watched.Set says so), decided under
one lock with the start's read.
- The head-moved test moved the head before the restart's read was answered, and read the state
heads before the bridge wrote it; it now waits for the stand-in's answer and watches heads.
- The owed test stopped the bridge while an outcome's publish was on its way (heard again after
the start), and an act said while the bridge stops can be handed to the stopped bridge's pull,
which the bus hands again only after the consumer's acknowledgement wait (30 s) past the
test's 20 s bound. It now hears the bridge's acknowledgements before the stop and waits the
consumer's acknowledgement wait for the act said meanwhile.
Builds: design 47 H §739; design 47 G §532; design 47 H-A-48
95 lines
4.1 KiB
Go
95 lines
4.1 KiB
Go
package bridge
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg"
|
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
|
)
|
|
|
|
// Design 47 G §4, §507, A-236; H §739: the watched branches are the registrations' by origin, and before the first
|
|
// registration the gate's source's, no branch fixed in code; a move of a watched branch is one head-moved naming the
|
|
// repository, the branch, the head read through the seat git's verb branch, the head held before and start; the read asks
|
|
// nothing but branch, and an unprotected branch's head is read like any other.
|
|
func TestAMoveOfAWatchedBranchIsOneHeadMoved(t *testing.T) {
|
|
w := &Watched{}
|
|
w.Set([]Registered{{Origin: "novox/mesh-sdk", Branches: []string{"main", "beta"}}}, []string{"main"})
|
|
for _, c := range []struct {
|
|
repo, branch string
|
|
want bool
|
|
}{{"novox/mesh-sdk", "beta", true}, {"novox/mesh-sdk", "feat/x", false}, {"novox/other", "main", false}} {
|
|
if got := w.Watches(c.repo, c.branch); got != c.want {
|
|
t.Errorf("registered: %s of %s watched %v, want %v", c.branch, c.repo, got, c.want)
|
|
}
|
|
}
|
|
if !watchedOf("main").Watches("novox/other", "main") || watchedOf("main").Watches("novox/other", "beta") {
|
|
t.Errorf("before the first registration the gate's source's branches are watched, of every repository")
|
|
}
|
|
// §532: only a registration adding a watched branch is adopted; the same registrations read again (a first view's
|
|
// values said after the start) add none.
|
|
regs := []Registered{{Origin: "novox/mesh-sdk", Branches: []string{"main", "beta"}}}
|
|
for _, c := range []struct {
|
|
name string
|
|
regs []Registered
|
|
want bool
|
|
}{
|
|
{"the same registrations again", regs, false},
|
|
{"a branch fewer", []Registered{{Origin: "novox/mesh-sdk", Branches: []string{"main"}}}, false},
|
|
{"a branch registered", regs, true},
|
|
{"a repository registered", append(regs, Registered{Origin: "novox/other", Branches: []string{"main"}}), true},
|
|
} {
|
|
if got := w.Set(c.regs, []string{"main"}); got != c.want {
|
|
t.Errorf("%s: added %v, want %v", c.name, got, c.want)
|
|
}
|
|
}
|
|
|
|
const head, before = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccccccccccccccccccccccc"
|
|
moved := Moved{Owner: "novox", Repo: "mesh-sdk", Branch: "feat/47-H"}
|
|
for _, c := range []struct {
|
|
name string
|
|
answer string
|
|
head string
|
|
fails bool
|
|
}{
|
|
{"a protected branch", `{"head":"` + head + `","protected":true}`, head, false},
|
|
{"an unprotected branch, read like any other (ADR 0682 §13)", `{"head":"` + head + `","protected":false}`, head, false},
|
|
{"an answer naming no head", `{"head":"abc"}`, "", true},
|
|
{"a refusal", `{"error":"no such branch","error-kind":"not-found"}`, "", true},
|
|
} {
|
|
var asked []string
|
|
ask := func(_ context.Context, key string, body any) (json.RawMessage, error) {
|
|
b, _ := json.Marshal(body)
|
|
asked = append(asked, key+" "+string(b))
|
|
return json.RawMessage(c.answer), nil
|
|
}
|
|
got, err := ReadHead(context.Background(), ask, moved)
|
|
if (err != nil) != c.fails || got != c.head {
|
|
t.Errorf("%s: %q %v, want %q, failing %v", c.name, got, err, c.head, c.fails)
|
|
}
|
|
if len(asked) != 1 || asked[0] != `seat:git.branch {"branch":"feat/47-H","repository":"novox/mesh-sdk"}` {
|
|
t.Errorf("%s: asked %v, want only the seat git's branch", c.name, asked)
|
|
}
|
|
}
|
|
|
|
for _, c := range []struct {
|
|
name string
|
|
before string
|
|
start bool
|
|
}{{"the first move", "", false}, {"a later move", before, false}, {"read at the start", before, true}} {
|
|
msg, err := HeadMoved(moved, head, c.before, c.start)
|
|
if err != nil {
|
|
t.Fatalf("%s: %v", c.name, err)
|
|
}
|
|
h, err := forgemsg.DecodeHeadMoved(msg.Data)
|
|
want := forgemsg.HeadMoved{V: forgemsg.Version, Repository: "novox/mesh-sdk", Branch: "feat/47-H", Head: head, Before: c.before, Start: c.start}
|
|
if err != nil || h != want || msg.Event != "forge.novox.mesh-sdk."+keys.EscapeName("feat/47-H")+".head-moved" {
|
|
t.Errorf("%s: %s %+v (%v), want %+v", c.name, msg.Event, h, err, want)
|
|
}
|
|
}
|
|
if _, err := HeadMoved(moved, head, head, false); err == nil {
|
|
t.Errorf("a head equal to the one held makes a message; want none")
|
|
}
|
|
}
|