Gate: the start pass asks again until no repository is left out (A-401)
The forge's git verbs may serve after the gate does; one pass with every head read refused wrote nothing and was never retried. Builds: design 47 G A-401
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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 "<repository>@<branch>".
|
||||
func (h *Holder) startSources(only string) (started, leftOut []string, err error) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user