Files
mesh-delivery/modules/mesh-delivery-indexer/internal/index/takein_source_test.go
T
jschoubben 04fe2e30fe H-A-497 indexer: a hand ask of a held branch answers at once
indexer_take_in_pending ran the whole chain of held take-ins inside the one
loop that acts on the takeins asks, minutes long, so its answer was cut and a
second ask waited behind it and answered "holds no source-moved". The ask
now starts the chain beside the loop and answers at once, "chain started at
source <n>, <m> wait"; an ask that meets a running chain answers its state.
The chain's state (branch, source being taken in, since, how many wait) is
the key chain.<branch> of the takeins state, written at each step and
deleted at the chain's end, skipped by the asks' loop and shown by
indexer_pending. A key a stop left is deleted at the indexer's start.

Builds: design 47 H2 H-A-497 (corrected), its addendum and its second addendum
2026-11-22 21:58:07 +01:00

490 lines
23 KiB
Go

package index
import (
"cmp"
"context"
"encoding/json"
"errors"
"fmt"
"reflect"
"slices"
"strings"
"sync"
"testing"
"time"
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
)
// takeInIndexer is an indexer that takes source revisions in from the catalogue repository's trees at f's commit, keeping its
// revisions and pins, and the take-in events it says (a take-in.pending kept as a taken with its why and skipped set).
func takeInIndexer(t *testing.T) (*Indexer, *memObjects, *[]meshcatalog.TakeInTaken, whole) {
t.Helper()
ix, _, f := newFormIndexerUnmerged(t, mod{"avahi", catalogueManifest(t, "avahi")})
reportToolchain(t, ix, "mesh-build-go", "novox", "go", "go1.27.1")
objects := newMemObjects(1 << 22)
ix.Revisions, ix.Pins, ix.PinsPending = objects, newMem(), func(context.Context) (uint64, error) { return 0, nil }
ix.Read = func(_ context.Context, repository, sha, _ string) (RepoRead, error) {
if repository != f.Repository || sha != f.Merge {
return RepoRead{}, errors.New("no such commit")
}
return RepoRead{Root: f.Root, Trees: f.Trees, Manifests: f.Manifests, Locks: f.Locks, Packages: f.Packages}, nil
}
ix.ReadFile = func(context.Context, string, string, string) ([]byte, error) { return nil, nil }
said := &[]meshcatalog.TakeInTaken{}
ix.SayTakeIn = func(_ context.Context, event, id string, body any) error {
if p, ok := body.(meshcatalog.TakeInPending); ok && event == "take-in.pending" && id == PendingID(p.Branch, p.Source) {
*said = append(*said, meshcatalog.TakeInTaken{Branch: p.Branch, Source: p.Source, Why: p.Why, Skipped: true})
return nil
}
tk, ok := body.(meshcatalog.TakeInTaken)
if event != "take-in.taken" || !ok || id != TakenID(tk.Branch, tk.Source) {
t.Errorf("said %s %s %+v, want take-in.taken under its branch and source", event, id, body)
}
*said = append(*said, tk)
return nil
}
return ix, objects, said, f
}
// Design 47 H §743, H-A-32, H-A-92, H-A-213 (1): a take-in writes one catalog revision <branch>.<n>, n the branch's newest + 1
// and its source the gate's, carrying its movers, pins it for the
// take-in's pipeline and says take-in.taken once; a redelivery writes nothing again and says the same; a revision with no mover
// pins nothing and says no entries; the old form is refused.
func TestASourceRevisionIsTakenInAsOneRevision(t *testing.T) {
ctx := context.Background()
ix, objects, said, f := takeInIndexer(t)
moved := meshdelivery.SourceMovedEvent{V: 1, Branch: "main", Source: 7, Call: "0123456789abcdef",
Heads: []meshdelivery.SourceMovedEventHeadsItem{{Repository: f.Repository, Commit: f.Merge}}}
taken, err := ix.TakeInSource(ctx, moved)
if err != nil {
t.Fatal(err)
}
if len(taken.Entries) != 1 || taken.Entries[0].Module != "avahi" || taken.Entries[0].Fingerprint == "" || taken.Entries[0].Commit != f.Merge ||
taken.Revision != 1 || taken.Branch != "main" || taken.Source != 7 || taken.Call != moved.Call {
t.Fatalf("taken %+v, want revision 1 (the branch's first) of source 7 of main with avahi as its one mover", taken)
}
rev, _, err := ReadRevision(ctx, objects, "main.1")
if err != nil || !reflect.DeepEqual(rev.Movers, taken.Entries) || rev.Source != 7 ||
rev.Call != moved.Call || rev.CallKind != meshcatalog.CatalogRevisionCallKindTakeIn { // H-A-215
t.Fatalf("main.1 = %+v (%v), want it kept carrying the movers", rev, err)
}
if v, _, found, _ := ix.Pins.Get(ctx, PinKey("main", 1)); !found {
t.Error("main.1 is not pinned for its pipeline")
} else {
var pv PinValue
if json.Unmarshal(v, &pv) != nil || !reflect.DeepEqual(pv.Records, []string{"pipeline.main.1"}) {
t.Errorf("main.1 is pinned by %s, want pipeline.main.1", v)
}
}
puts := objects.puts
again, err := ix.TakeInSource(ctx, moved)
if err != nil || objects.puts != puts || !reflect.DeepEqual(again, taken) {
t.Errorf("a redelivery wrote %d objects and said %+v (%v), want none and the same", objects.puts-puts, again, err)
}
same := moved
same.Source, same.Call = 8, "fedcba9876543210"
none, err := ix.TakeInSource(ctx, same)
if err != nil || len(none.Entries) != 0 || none.Revision != 2 || none.Source != 8 {
t.Errorf("a revision moving no fingerprint said %+v (%v), want revision 2 of source 8 with no entries", none, err)
}
if _, _, found, _ := ix.Pins.Get(ctx, PinKey("main", 2)); found {
t.Error("a take-in with no mover pinned its revision")
}
if _, _, err := ReadRevision(ctx, objects, "main.2"); err != nil {
t.Errorf("main.2 is not kept: %v", err)
}
if len(*said) != 3 {
t.Errorf("said %d take-in.taken, want 3", len(*said))
}
old := moved
old.Call = ""
if _, err := ix.TakeInSource(ctx, old); !errors.Is(err, ErrOldForm) {
t.Errorf("a source-moved with no call answered %v, want ErrOldForm", err)
}
// Design 47 H2 §815: a move of a source-only registration's branch (a repository with no manifest) is taken in as a
// take-in with no movers.
read := ix.Read
ix.Read = func(ctx context.Context, repository, sha, dir string) (RepoRead, error) {
if repository == "novox/hq" {
return RepoRead{Root: "1111111111111111111111111111111111111111", Trees: map[string]string{}, Manifests: map[string]string{}}, nil
}
return read(ctx, repository, sha, dir)
}
hq := meshdelivery.SourceMovedEvent{V: 1, Branch: "main", Source: 9, Call: "00112233445566aa",
Heads: []meshdelivery.SourceMovedEventHeadsItem{{Repository: "novox/hq", Commit: "2222222222222222222222222222222222222222"}}}
if src, err := ix.TakeInSource(ctx, hq); err != nil || len(src.Entries) != 0 || src.Revision != 3 || src.Source != 9 {
t.Errorf("a source-only repository's move said %+v (%v), want revision 3 of source 9 with no movers", src, err)
}
ix.Read = read
// Design 47 H2 §803, H-A-409: a take-in says what it waits on, in the journal, in takeins and past five minutes as a finding.
t.Run("a take-in says what it waits on", func(t *testing.T) {
running := newMem()
ix.TakeIns = running
ix.Findings = newFindings()
// The take-in's end removes its waiting-on.
if err := running.Create(ctx, RunningKey(10), []byte(`{"source":10}`)); err != nil {
t.Fatal(err)
}
next := moved
next.Source, next.Call = 10, "00112233445566ff"
if _, err := ix.TakeInSource(ctx, next); err != nil {
t.Fatal(err)
}
if _, _, found, _ := running.Get(ctx, RunningKey(10)); found {
t.Error("the take-in's end left its waiting-on in takeins")
}
start := time.Date(2026, 11, 22, 1, 0, 0, 0, time.UTC)
now := start
timers := make(chan context.CancelFunc)
var mu sync.Mutex
var asked []time.Duration // the bounds the wait asked, in order
var lines []string
wrote := make(chan struct{}, 1)
findings := newFindings()
w := &Indexer{Module: testSelf, TakeIns: running, Findings: findings, Now: func() time.Time { mu.Lock(); defer mu.Unlock(); return now },
Bound: func(parent context.Context, d time.Duration) (context.Context, context.CancelFunc) {
mu.Lock()
asked = append(asked, d)
mu.Unlock()
b, cancel := context.WithCancel(parent)
timers <- cancel
return b, cancel
},
Logf: func(format string, args ...any) {
mu.Lock()
defer mu.Unlock()
lines = append(lines, fmt.Sprintf(format, args...))
}}
w.Findings = findingsSignal{findings, wrote}
listing := func(answerAfter, line, bound time.Duration) {
t.Helper()
mu.Lock()
now, lines, asked = start, nil, nil
mu.Unlock()
release, res := make(chan struct{}), make(chan error)
go func() {
_, err := waited(w.withTakeIn(ctx, "main", 9), "git", "trees", func() (int, error) { <-release; return 1, nil })
res <- err
}()
first := <-timers
if answerAfter < line {
close(release)
<-res
return
}
mu.Lock()
now = start.Add(70 * time.Second)
mu.Unlock()
first()
second := <-timers // asked once the line is said and the waiting-on written
if answerAfter >= bound {
second()
<-wrote
if h := findings.Held(); len(h) != 1 || h[0].Kind != TakeInWaitingKind || h[0].Scope != mcc.ScopeMerge || h[0].ID != "9" {
t.Errorf("after %s: findings %+v, want take-in-waiting of merge 9", answerAfter, h)
}
}
close(release)
if err := <-res; err != nil {
t.Fatal(err)
}
}
// The bounds are the settings take-in-waiting-line and take-in-waiting-bound, 1m and 5m when unset (H-A-461 (2)): the
// wait asks the line, then the rest to the bound.
for _, c := range []struct {
after, line, bound time.Duration // line and bound zero: the settings unset
lines int
finding bool
}{{30 * time.Second, 0, 0, 0, false}, {70 * time.Second, 0, 0, 1, false}, {6 * time.Minute, 0, 0, 1, false},
{6 * time.Minute, 2 * time.Minute, 10 * time.Minute, 1, false}} {
w.WaitingLine, w.WaitingBound = c.line, c.bound
line, bound := cmp.Or(c.line, time.Minute), cmp.Or(c.bound, 5*time.Minute)
listing(c.after, line, bound)
mu.Lock()
got, gotAsked := slices.Clone(lines), slices.Clone(asked)
mu.Unlock()
wantAsked := []time.Duration{line}
if c.after >= line {
wantAsked = append(wantAsked, bound-line)
}
if !slices.Equal(gotAsked, wantAsked) {
t.Errorf("answered after %s (line %s, bound %s): bounds asked %v, want %v", c.after, c.line, c.bound, gotAsked, wantAsked)
}
if len(got) != c.lines || (c.lines == 1 && !strings.Contains(got[0], "waits on git trees since 2026-11-22T01:00:00Z")) {
t.Errorf("answered after %s: lines %q, want %d naming git trees and since when", c.after, got, c.lines)
}
r, err := ReadRunning(ctx, running)
want := c.lines == 1
if err != nil || want != (len(r) == 1) || (want && (r[0].Source != 9 || r[0].Branch != "main" || r[0].WaitingOn != WaitingOn{Part: "git", Verb: "trees", Since: start})) {
t.Errorf("answered after %s: running %+v (%v), want waiting-on git trees since %s: %v", c.after, r, err, start, want)
}
if len(findings.Held()) != 0 {
t.Errorf("answered after %s: take-in-waiting still raised: %+v", c.after, findings.Held())
}
w.endTakeIn(ctx, 9)
}
})
}
// findingsSignal is a finding writer that says each write it passes on.
type findingsSignal struct {
*memFindings
wrote chan struct{}
}
func (f findingsSignal) Write(ctx context.Context, x mcseat.Finding) error {
err := f.memFindings.Write(ctx, x)
f.wrote <- struct{}{}
return err
}
// Design 47 H §768, §743, H-A-19: a branch's first source revision (start true) is taken in with no mover, says take-in.taken
// with no entries and pins nothing; its entries are the base a later take-in's movers are judged against.
func TestAFirstSourceRevisionIsTakenInWithNoMover(t *testing.T) {
ctx := context.Background()
ix, objects, _, f := takeInIndexer(t)
start := meshdelivery.SourceMovedEvent{V: 1, Branch: "main", Source: 1, Call: "seed.operator.20261120", Start: true,
Heads: []meshdelivery.SourceMovedEventHeadsItem{{Repository: f.Repository, Commit: f.Merge}}}
taken, err := ix.TakeInSource(ctx, start)
if err != nil || len(taken.Entries) != 0 || taken.Revision != 1 {
t.Fatalf("the first revision said %+v (%v), want revision 1 with no entries", taken, err)
}
if keys, _ := ix.Pins.Keys(ctx); len(keys) != 0 {
t.Errorf("the first revision pinned %v", keys)
}
if _, entries, err := ReadRevision(ctx, objects, "main.1"); err != nil || len(entries) != 1 || entries[0].Commit != f.Merge {
t.Fatalf("main.1 holds %+v (%v), want avahi at the head", entries, err)
}
next := start
next.Source, next.Call, next.Start = 2, "0123456789abcdef", false
if again, err := ix.TakeInSource(ctx, next); err != nil || len(again.Entries) != 0 {
t.Errorf("a later take-in of the same head said %+v (%v), want no mover against the first revision", again, err)
}
}
// Design 47 H §743, H-A-135: at a branch's take-in the earlier model's revisions (trunk.<n>, branch.<branch>.<n>) no record
// pins are dropped, one a record pins stays, and the branch's newest revision is the current one, no longer the newest trunk.
func TestATakeInDropsTheEarlierFormsNoRecordPins(t *testing.T) {
ctx := context.Background()
ix, objects, _, f := takeInIndexer(t)
for _, n := range []string{"trunk.527", "trunk.528", "branch.master.1"} {
_, rev, _ := RevisionGroup(n)
raw, _ := json.Marshal(meshcatalog.CatalogRevision{Revision: rev, Kind: "trunk", Source: 1000 + rev})
if err := objects.Put(ctx, n, raw); err != nil {
t.Fatal(err)
}
}
if err := ix.pin(ctx, "trunk.527", "pipeline.old"); err != nil {
t.Fatal(err)
}
start := meshdelivery.SourceMovedEvent{V: 1, Branch: "main", Source: 1, Call: "seed.operator.20261120", Start: true,
Heads: []meshdelivery.SourceMovedEventHeadsItem{{Repository: f.Repository, Commit: f.Merge}}}
if _, err := ix.TakeInSource(ctx, start); err != nil {
t.Fatal(err)
}
a, err := ListRevisions(ctx, objects, false)
if err != nil {
t.Fatal(err)
}
var got []string
for _, r := range a.Revisions {
got = append(got, fmt.Sprintf("%s current=%t", r.Name, r.Current))
}
if want := []string{"main.1 current=true", "trunk.527 current=false"}; !reflect.DeepEqual(got, want) {
t.Errorf("kept %v, want %v: the unpinned earlier forms dropped, the pinned one kept, main.1 current", got, want)
}
}
// Design 47 H §769: the take-in of a source revision moving the catalogue repository reads `predefined` from that commit's
// trees, and one changing a predefined key rewrites it.
func TestATakeInOfTheCatalogsCommitRewritesPredefined(t *testing.T) {
ctx := context.Background()
ix, _, _, f := takeInIndexer(t)
ix.Predefined = newMem()
ix.Contains = func(context.Context, string, string, string) (bool, error) { return false, nil }
ix.Read = func(_ context.Context, _, _, _ string) (RepoRead, error) {
return RepoRead{Root: f.Root, Trees: f.Trees, Manifests: f.Manifests, Locks: f.Locks, Packages: f.Packages}, nil
}
lists := map[string]string{"c1": `{"keys":["a"]}`, "c2": `{"keys":["a","b"]}`}
ix.ReadFile = func(_ context.Context, _, sha, path string) ([]byte, error) {
if path != predefinedFile {
return nil, nil
}
return []byte(lists[sha]), nil
}
for i, commit := range []string{"c1", "c2"} {
moved := meshdelivery.SourceMovedEvent{V: 1, Branch: "main", Source: int64(i + 1), Call: "0123456789abcde" + commit[1:],
Heads: []meshdelivery.SourceMovedEventHeadsItem{{Repository: catalogueRepo, Commit: commit}}}
if _, err := ix.TakeInSource(ctx, moved); err != nil {
t.Fatal(err)
}
raw, _, found, _ := ix.Predefined.Get(ctx, PredefinedListKey)
var kept struct {
Commit string `json:"commit"`
List json.RawMessage `json:"list"`
}
if !found || json.Unmarshal(raw, &kept) != nil || kept.Commit != commit || string(kept.List) != lists[commit] {
t.Errorf("after the take-in of %s predefined holds %s, want its list at %s", commit, raw, commit)
}
}
}
// Design 47 H §744 (acceptance test 116): a take-in the full catalog store cannot write is held, said once per source as
// take-in.pending with branch, source and why, and room is said once the store has room again; taken in then.
func TestATakeInOnAFullStoreIsHeldAndSaidOnce(t *testing.T) {
ctx := context.Background()
ix, objects, said, f := takeInIndexer(t)
objects.capacity = 10
ix.Held = newMem()
moved := meshdelivery.SourceMovedEvent{V: 1, Branch: "main", Source: 3, Call: "0123456789abcdef",
Heads: []meshdelivery.SourceMovedEventHeadsItem{{Repository: f.Repository, Commit: f.Merge}}}
var rooms int
ix.SayFill = func(_ context.Context, event, _ string, _ meshcatalog.Fill) error {
if event == meshcatalog.EventRoom {
rooms++
}
return nil
}
for range 2 {
if _, err := ix.TakeInSource(ctx, moved); !errors.Is(err, ErrObjectsFull) {
t.Fatalf("a full store answered %v, want ErrObjectsFull", err)
}
}
if len(*said) != 1 || (*said)[0].Branch != "main" || (*said)[0].Source != 3 || (*said)[0].Why == "" || !(*said)[0].Skipped {
t.Fatalf("said %+v, want one take-in.pending of main 3 with its why", *said)
}
if held, err := ReadHeld(ctx, ix.Held); err != nil || len(held) != 1 || held[0].Branch != "main" || held[0].Source != 3 || held[0].Why == "" {
t.Errorf("held = %+v (%v), want main's source revision 3 and why", held, err)
}
// H-A-118: the held value carries the event whole, and a later source of the branch is held behind it, in order.
next := moved
next.Source, next.Call = 4, "1123456789abcdef"
if behind, err := ix.HoldBehind(ctx, next); err != nil || !behind {
t.Fatalf("the later source held behind: %v (%v)", behind, err)
}
if held, _ := ReadHeld(ctx, ix.Held); len(held) != 2 || held[0].Source != 3 || held[1].Source != 4 || held[0].Call != moved.Call ||
len(held[0].Heads) != 1 || held[0].Heads[0] != moved.Heads[0] || !reflect.DeepEqual(held[0].Event(), moved) {
t.Fatalf("held = %+v, want 3 then 4, each with its event whole", held)
}
// H-A-497: behind them a source whose head the forge does not answer, and one more behind it.
for _, n := range []struct {
source int64
commit string
}{{5, "c-unread"}, {6, f.Merge}} {
e := moved
e.Source, e.Call, e.Heads = n.source, fmt.Sprintf("%d123456789abcdef", n.source), []meshdelivery.SourceMovedEventHeadsItem{{Repository: f.Repository, Commit: n.commit}}
if behind, err := ix.HoldBehind(ctx, e); err != nil || !behind {
t.Fatalf("source %d held behind: %v (%v)", n.source, behind, err)
}
}
var lines []string
ix.Logf = func(format string, args ...any) { lines = append(lines, fmt.Sprintf(format, args...)) }
ix.TakeIns = newMem()
// H-A-497 addendum: while the chain runs, its key names the source being taken in and how many wait behind it.
var steps []string
read := ix.Read
ix.Read = func(ctx context.Context, repository, sha, dir string) (RepoRead, error) {
if c, ok, _ := ix.ChainOf(ctx, "main"); ok {
steps = append(steps, fmt.Sprintf("%d/%d", c.Source, c.Waiting))
}
return read(ctx, repository, sha, dir)
}
objects.capacity = 1 << 22
if ok, err := ix.RoomAgain(ctx); err != nil || !ok || rooms != 1 {
t.Fatalf("room said %v %d times (%v), want once the store has room", ok, rooms, err)
}
// H-A-114, H-A-497: on room (and at start, and by hand) the held ones are taken in again from the state held alone, in
// their order, each next one at once and said in the journal, until one is held again: those behind it stay held.
ix.TakeHeldIn(ctx)
var taken []int64
for _, e := range *said {
if !e.Skipped {
taken = append(taken, e.Source)
}
}
if !reflect.DeepEqual(taken, []int64{3, 4}) {
t.Errorf("taken again on room: %v of %+v, want 3 then 4", taken, *said)
}
if held, _ := ReadHeld(ctx, ix.Held); len(held) != 2 || held[0].Source != 5 || held[1].Source != 6 {
t.Errorf("held = %+v after the take-in, want 5 held again and 6 behind it", held)
}
for _, want := range []string{
"take-in: held source 4 of main taken in next, after 3 (H-A-497)",
"take-in: held source 5 of main taken in next, after 4 (H-A-497)",
} {
if !slices.Contains(lines, want) {
t.Errorf("the journal holds no line %q: %q", want, lines)
}
}
for _, l := range lines {
if strings.Contains(l, "held source 6 of main taken in") {
t.Errorf("source 6 was taken in behind a held one: %q", l)
}
}
if !slices.Contains(steps, "4/2") || !slices.Contains(steps, "5/1") {
t.Errorf("the chain's key read at each take-in %v, want main at 4 with 2 waiting and at 5 with 1", steps)
}
// H-A-497 addendum: the chain's key in the state takeins goes at its end, here its first held again, and one a stop
// left is deleted at the start.
if chains, err := ReadChains(ctx, ix.TakeIns); err != nil || len(chains) != 0 {
t.Errorf("chains %+v (%v) after the chain stopped, want none", chains, err)
}
ix.writeChain(ctx, HeldChain{Branch: "main", Source: 9, Waiting: 1})
if ix.EndChains(ctx); func() bool { c, _ := ReadChains(ctx, ix.TakeIns); return len(c) != 0 }() {
t.Error("a chain's key left by a stop stays after the start")
}
ix.Read = read
ix.Logf, ix.TakeIns = nil, nil
for _, src := range []int64{5, 6} {
ix.unhold(ctx, "main", src)
}
// A skip ends a held source revision unwritten: take-in.taken with no entries, skipped, by and why; held is deleted.
ix.hold(ctx, meshdelivery.SourceMovedEvent{Branch: "nox-mesh", Source: 9, Call: "fedcba9876543210"}, "the catalog store is full")
if err := ix.SkipTakeIn(ctx, meshdelivery.SourceMovedEvent{Branch: "nox-mesh", Source: 9, Call: "fedcba9876543210"}, "operator", "a stale source"); err != nil {
t.Fatal(err)
}
if last := (*said)[len(*said)-1]; !last.Skipped || last.By != "operator" || last.Why != "a stale source" || len(last.Entries) != 0 || last.Source != 9 {
t.Errorf("the skip said %+v, want take-in.taken skipped by the operator with its why", last)
}
if held, _ := ReadHeld(ctx, ix.Held); len(held) != 0 {
t.Errorf("held = %+v after the skip, want none", held)
}
}
// Design 47 H §743, §768, H-A-129, H-A-130: the gate's source revision read through its verb source is taken in as a heard
// source-moved of it would be: start true when the view keeps no revision of the branch, every repository it names a head;
// one the view keeps at or above is not taken again; a later one is judged against the newest kept, start false.
func TestASourceRevisionReadFromTheGateIsTakenInOnce(t *testing.T) {
ctx := context.Background()
ix, _, said, f := takeInIndexer(t)
answer := meshdelivery.SourceAnswer{Branch: "main", Revision: 1, Call: "0123456789abcdef",
Repositories: []meshdelivery.SourceHead{{Repository: f.Repository, Trunk: "main", Head: f.Merge}}}
e, take, err := ix.SourceToTake(ctx, "main", answer)
want := meshdelivery.SourceMovedEvent{V: 1, Branch: "main", Source: 1, Call: answer.Call, Start: true,
Heads: []meshdelivery.SourceMovedEventHeadsItem{{Repository: f.Repository, Commit: f.Merge}}}
if err != nil || !take || !reflect.DeepEqual(e, want) {
t.Fatalf("a branch the view keeps none of answered %+v, %t (%v); want %+v taken", e, take, err, want)
}
if taken, err := ix.TakeInSource(ctx, e); err != nil || len(taken.Entries) != 0 || taken.Revision != 1 {
t.Fatalf("the first revision read from the gate said %+v (%v), want revision 1 with no mover", taken, err)
}
if _, take, err := ix.SourceToTake(ctx, "main", answer); take || err != nil {
t.Errorf("a revision the view keeps is taken again (%v)", err)
}
if _, take, _ := ix.SourceToTake(ctx, "nox-mesh", meshdelivery.SourceAnswer{Branch: "nox-mesh"}); take {
t.Error("a branch the gate keeps no revision of is taken in")
}
answer.Revision, answer.Call = 2, "1123456789abcdef"
if e, take, err := ix.SourceToTake(ctx, "main", answer); err != nil || !take || e.Start || e.Source != 2 {
t.Errorf("a later revision answered %+v, %t (%v); want revision 2 taken, start false", e, take, err)
}
if len(*said) != 1 {
t.Errorf("said %d take-in.taken, want 1", len(*said))
}
}