diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go index b9bc97998..1992a61e6 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go @@ -125,19 +125,6 @@ func run(h *Holder, l *listening) { } } -// startSourcesAtStart starts the sources of the watched branches no key holds, retrying until the registrations can be read. -func startSourcesAtStart(h *Holder) { - for wait := 2 * time.Second; ; wait = min(wait*2, time.Minute) { - started, err := h.StartSources() - if err == nil { - logf("[mesh-delivery] the sources started from the forge at the start: %v", started) - return - } - logf("[mesh-delivery] the sources cannot be started yet (%v); asking again in %s", err, wait) - time.Sleep(wait) - } -} - // switchToRecords carries the groups in flight into their delivery records (switch.go), retrying until it can: no event is // taken before, so no outcome reaches a record the switch has not opened yet. func switchToRecords(h *Holder, l *listening) { diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcestart.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcestart.go index dbd772a1a..2fd8e6145 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcestart.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcestart.go @@ -13,6 +13,7 @@ import ( "sort" "strconv" "strings" + "time" "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" gitseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git" @@ -89,6 +90,24 @@ func (h *Holder) StartSources() ([]string, error) { return started, err } +// startSleep waits between the start's passes; a test replaces it. +var startSleep = time.Sleep + +// startSourcesAtStart starts the sources at the gate's start, and asks again, as switchToRecords does (2 s doubling to a +// minute), until a pass reads the registrations and leaves no repository out: the forge's verbs may serve after the gate +// does (A-401). +func startSourcesAtStart(h *Holder) { + for wait := 2 * time.Second; ; wait = min(wait*2, time.Minute) { + started, leftOut, err := h.startSources("") + if err == nil && len(leftOut) == 0 { + h.logf("[mesh-delivery] the sources started from the forge at the start: %v", started) + return + } + h.logf("[mesh-delivery] the sources are not all started yet (started %v, left out %v, %v); asking again in %s", started, leftOut, err, wait) + startSleep(wait) + } +} + // startSources starts the branches no key holds, or only branch when it is named; it answers the branches written and the // repositories left out as "@". func (h *Holder) startSources(only string) (started, leftOut []string, err error) { diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcetools_test.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcetools_test.go index 0ba9afc6f..892df4ea6 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcetools_test.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcetools_test.go @@ -259,3 +259,20 @@ func TestRegistrationChangedAndTheStartPassStartABranch(t *testing.T) { }) } } + +// Design 47 G A-401: a start pass that left a repository out is not done: it asks again, doubling its wait, until none is left out. +func TestTheStartAsksAgainWhileARepositoryIsLeftOut(t *testing.T) { + var waits []time.Duration + old := startSleep + startSleep = func(d time.Duration) { waits = append(waits, d) } + defer func() { startSleep = old }() + src := &branchSource{memSource{vals: map[string]Source{}}} + forge := &fakeForge{fail: true, heads: map[string]string{"o/f1@master": "c3"}} + startSleep = func(d time.Duration) { waits = append(waits, d); forge.fail = len(waits) < 2 } + h := &Holder{Now: time.Now, Source: src, Forge: forge, Logf: func(string, ...any) {}, + Catalog: fakeCatalog{regs: []meshcatalog.Registration{{Module: "f1", Origin: "o/f1", Branches: []string{"master"}}}}} + startSourcesAtStart(h) + if !reflect.DeepEqual(waits, []time.Duration{2 * time.Second, 4 * time.Second}) || src.vals["master"].Heads["o/f1"] != "c3" { + t.Fatalf("waits %v source %+v", waits, src.vals) + } +}