mesh-delivery-gate: the start pass runs once, asking again only while the registrations cannot be read
Builds: design 47 G A-442, A-401
This commit is contained in:
@@ -93,17 +93,20 @@ func (h *Holder) StartSources() ([]string, error) {
|
||||
// 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).
|
||||
// errRegistrationsUnread is a start pass's error when the registrations cannot be read.
|
||||
var errRegistrationsUnread = errors.New("the registrations cannot be read")
|
||||
|
||||
// startSourcesAtStart runs the start pass once (A-442), and asks again, as switchToRecords does (2 s doubling to a minute),
|
||||
// only while the registrations cannot be read: the seat mesh-catalog may serve after the gate does. A repository a pass
|
||||
// leaves out is said by the pass, and added at the next registration change or by gate_source_start (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)
|
||||
if err == nil || !errors.Is(err, errRegistrationsUnread) {
|
||||
h.logf("[mesh-delivery] the sources started from the forge at the start: %v; left out %v; %v", started, leftOut, err)
|
||||
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)
|
||||
h.logf("[mesh-delivery] the registrations cannot be read yet (%v); asking again in %s", err, wait)
|
||||
startSleep(wait)
|
||||
}
|
||||
}
|
||||
@@ -118,7 +121,7 @@ func (h *Holder) startSources(only string) (started, leftOut []string, err error
|
||||
defer h.startMu.Unlock()
|
||||
regs, err := h.Catalog.Registrations()
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("the registrations cannot be read: %w", err)
|
||||
return nil, nil, fmt.Errorf("%w: %w", errRegistrationsUnread, err)
|
||||
}
|
||||
watched := watchedRepositories(regs.Registrations)
|
||||
if only != "" {
|
||||
|
||||
@@ -260,19 +260,52 @@ 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)
|
||||
// Design 47 G A-442: the start pass runs once; it asks again, doubling its wait, only while the registrations cannot be read,
|
||||
// and a repository left out is said, not waited for.
|
||||
func TestTheStartAsksAgainOnlyWhileTheRegistrationsCannotBeRead(t *testing.T) {
|
||||
regs := []meshcatalog.Registration{{Module: "f1", Origin: "o/f1", Branches: []string{"master"}}}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
unreadFor int // passes the registrations cannot be read
|
||||
forgeFail bool // the forge cannot name the head
|
||||
waits []time.Duration
|
||||
started bool
|
||||
}{
|
||||
{"registrations unread twice", 2, false, []time.Duration{2 * time.Second, 4 * time.Second}, true},
|
||||
{"a repository left out is not waited for", 0, true, nil, false},
|
||||
} {
|
||||
t.Run(c.name, func(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: c.forgeFail, heads: map[string]string{"o/f1@master": "c3"}}
|
||||
cat := &flakyCatalog{fakeCatalog: fakeCatalog{regs: regs}, failFor: c.unreadFor}
|
||||
var said []string
|
||||
h := &Holder{Now: time.Now, Source: src, Forge: forge, Catalog: cat,
|
||||
Logf: func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) }}
|
||||
startSourcesAtStart(h)
|
||||
if !reflect.DeepEqual(waits, c.waits) || (src.vals["master"].Heads["o/f1"] == "c3") != c.started {
|
||||
t.Fatalf("waits %v source %+v", waits, src.vals)
|
||||
}
|
||||
if c.forgeFail && !strings.Contains(strings.Join(said, "\n"), "o/f1@master") {
|
||||
t.Fatalf("the left-out repository is not said: %v", said)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// flakyCatalog cannot read the registrations for its first failFor asks.
|
||||
type flakyCatalog struct {
|
||||
fakeCatalog
|
||||
failFor int
|
||||
}
|
||||
|
||||
func (f *flakyCatalog) Registrations() (meshcatalog.RegistrationsAnswer, error) {
|
||||
if f.failFor > 0 {
|
||||
f.failFor--
|
||||
return meshcatalog.RegistrationsAnswer{}, errors.New("not served yet")
|
||||
}
|
||||
return f.fakeCatalog.Registrations()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user