|
|
|
@@ -412,26 +412,31 @@ func absent(v []byte) bool { return v == nil }
|
|
|
|
|
func TestIndexerWhole(t *testing.T) {
|
|
|
|
|
const (
|
|
|
|
|
c10, c11, c12, c13 = "1010101010101010101010101010101010101010", "1111111111111111111111111111111111111111", "1212121212121212121212121212121212121212", "1313131313131313131313131313131313131313"
|
|
|
|
|
c15, c16 = "1515151515151515151515151515151515151515", "1616161616161616161616161616161616161616"
|
|
|
|
|
unread = "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef"
|
|
|
|
|
)
|
|
|
|
|
var forge *forgeCommits
|
|
|
|
|
var heard *takeIns
|
|
|
|
|
var pins, held, takeinsKV, regs, runs, status jetstream.KeyValue
|
|
|
|
|
var pins, held, takeinsKV, regs, runs, status, heardKV jetstream.KeyValue
|
|
|
|
|
js, ctx, candidates, _, restart := startIndexerRun(t, func(context.Context, buildLog) {}, func(ctx context.Context, js jetstream.JetStream) {
|
|
|
|
|
heard = hearTakeIns(t, js.Conn())
|
|
|
|
|
forge = serveCommits(t, js.Conn())
|
|
|
|
|
for commit, tree := range map[string]string{c10: "t10", c11: "t11", c12: "t12", c13: "t13"} {
|
|
|
|
|
for commit, tree := range map[string]string{c10: "t10", c11: "t11", c12: "t12", c13: "t13", c15: "t15", c16: "t16"} {
|
|
|
|
|
forge.put(commit, catalogueAt(t, tree))
|
|
|
|
|
}
|
|
|
|
|
var err error
|
|
|
|
|
for _, b := range []struct {
|
|
|
|
|
state string
|
|
|
|
|
kv *jetstream.KeyValue
|
|
|
|
|
}{{index.HeldState, &held}, {index.TakeInsState, &takeinsKV}, {index.RunsState, &runs}, {views.StatusState, &status}} {
|
|
|
|
|
}{{index.HeldState, &held}, {index.TakeInsState, &takeinsKV}, {index.RunsState, &runs}, {views.StatusState, &status}, {index.HeardState, &heardKV}} {
|
|
|
|
|
if *b.kv, err = js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: index.Bucket(testIndexer, b.state), History: 64}); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// The indexer's findings, which the grants part makes from its manifest's state findings (AC-I9 reads them).
|
|
|
|
|
if _, err = js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: findingsBucket, History: 1}); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
regs = registerAvahi(t, ctx, js, "main", "beta")
|
|
|
|
|
tc, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: index.ToolchainsBucket("mesh-build-go"), History: 1})
|
|
|
|
|
if err != nil {
|
|
|
|
@@ -452,13 +457,17 @@ func TestIndexerWhole(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Design 47 H2 H-A-578 (2), H-A-651 (AC-I9): an event of a subject the manifest no longer consumes, which the durable's
|
|
|
|
|
// filter still holds, is acknowledged with no work (the unit test of ackDropped holds that it says the subject once).
|
|
|
|
|
// Two rounds: the hub hands one message at a time and says an unhandled one's finding after its acknowledgement, so the
|
|
|
|
|
// second round's acknowledgements come after the first round's findings were written, if any.
|
|
|
|
|
var last uint64
|
|
|
|
|
for _, subject := range droppedSubjects {
|
|
|
|
|
ack, err := js.Publish(ctx, subject, []byte(`{}`))
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
for range 2 {
|
|
|
|
|
for _, subject := range droppedSubjects {
|
|
|
|
|
ack, err := js.Publish(ctx, subject, []byte(`{}`))
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
last = ack.Sequence
|
|
|
|
|
}
|
|
|
|
|
last = ack.Sequence
|
|
|
|
|
}
|
|
|
|
|
cons, err := testAccount.EventConsumer(ctx, js, views0Stream)
|
|
|
|
|
if err != nil {
|
|
|
|
@@ -476,6 +485,17 @@ func TestIndexerWhole(t *testing.T) {
|
|
|
|
|
t.Fatalf("the dropped subjects events are not acknowledged: ack floor %d, want %d", info.AckFloor.Stream, last)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// AC-I9: the hub says no finding event-unhandled of them, since the subjects have a handler (without it the hub
|
|
|
|
|
// acknowledges them just the same, so the acknowledgement above does not hold it).
|
|
|
|
|
findings, err := js.KeyValue(ctx, findingsBucket)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if e, err := findings.Get(ctx, views.FindingKey(views.FindingScope, keys.EscapeName(testIndexer), views.EventUnhandledKind)); err == nil {
|
|
|
|
|
t.Errorf("the dropped subjects' events raised the finding %s: %s", e.Key(), e.Value())
|
|
|
|
|
} else if !errors.Is(err, jetstream.ErrKeyNotFound) {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
// The first revision: no mover, no pin; its entries are the base.
|
|
|
|
|
sayMoved(t, ctx, js, "main", 10, c10, true)
|
|
|
|
|
// A revision's number is the indexer's own count, the branch's newest + 1 (design 47 H-A-213 (1)): the later take-ins of
|
|
|
|
@@ -695,6 +715,58 @@ func TestIndexerWhole(t *testing.T) {
|
|
|
|
|
t.Errorf("gamma.1 is not kept: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Design 47 H2 H-A-566, H-A-572, H-A-595, H-A-608 (AC-I7a, AC-I7b, AC-I7c, AC-I8): a pipeline that ended failed with a module
|
|
|
|
|
// unfinished pins the revision the module comes from and its base under the module's failed record; a cancelled end of a kept
|
|
|
|
|
// mover pins its kept revision and that revision's base; the record dropped by hand leaves the pins' other records; a module
|
|
|
|
|
// that leaves the registrations frees its record.
|
|
|
|
|
failedRecord := index.FailedRecord("main", "avahi")
|
|
|
|
|
lacks := func(record string) func([]byte) bool {
|
|
|
|
|
return func(v []byte) bool {
|
|
|
|
|
var p index.PinValue
|
|
|
|
|
return v == nil || (json.Unmarshal(v, &p) == nil && !slices.Contains(p.Records, record))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
endedPipeline := func(pipeline string, revision int64, outcome string, movers []meshpipelinerunner.MoverEnded, unfinished ...string) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
raw, _ := json.Marshal(meshpipelinerunner.PipelineEnded{V: 1, Pipeline: pipeline, Branch: "main", Source: revision, Revision: revision,
|
|
|
|
|
Outcome: outcome, Movers: movers, Unfinished: unfinished})
|
|
|
|
|
if _, err := js.Publish(ctx, meshpipelinerunner.SubjectPipelineEnded("main", strconv.FormatInt(revision, 10)), raw); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sayMoved(t, ctx, js, "main", 15, c15, false)
|
|
|
|
|
take15 := heard.next(t, "main", 15)
|
|
|
|
|
r15, p15 := take15.Revision, fmt.Sprintf("main.%d", take15.Revision)
|
|
|
|
|
r14 := r15 - 1
|
|
|
|
|
untilKey(t, ctx, pins, index.PinKey("main", r15), pinned("pipeline."+p15))
|
|
|
|
|
untilKey(t, ctx, pins, index.PinKey("main", r14), pinned("pipeline."+p15))
|
|
|
|
|
endedPipeline(p15, r15, meshpipelinerunner.PipelineEndedOutcomeFailed, nil, "avahi") // AC-I7a: avahi unfinished
|
|
|
|
|
untilKey(t, ctx, pins, index.PinKey("main", r15), pinned(failedRecord))
|
|
|
|
|
untilKey(t, ctx, pins, index.PinKey("main", r14), pinned(failedRecord)) // its base
|
|
|
|
|
sayMoved(t, ctx, js, "main", 16, c16, false)
|
|
|
|
|
take16 := heard.next(t, "main", 16)
|
|
|
|
|
r16, p16 := take16.Revision, fmt.Sprintf("main.%d", take16.Revision)
|
|
|
|
|
untilKey(t, ctx, pins, index.PinKey("main", r15), pinned(failedRecord, "pipeline."+p16)) // main.16's base
|
|
|
|
|
// AC-I8: indexer_pin_drop with record drops that one record from every pin; the pin holding another record keeps it.
|
|
|
|
|
pinTools := index.PinsTools(kvStore{pins}, objects, askVia(t, ctx, takeinsKV), time.Now, func(string, string) error { return nil })
|
|
|
|
|
if _, err := toolNamed(t, pinTools, index.PinDropTool).Run(map[string]any{"record": failedRecord, "why": "the failed mover passed on its own"}); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
untilKey(t, ctx, pins, index.PinKey("main", r15), pinned("pipeline."+p16))
|
|
|
|
|
untilKey(t, ctx, pins, index.PinKey("main", r14), lacks(failedRecord))
|
|
|
|
|
untilKey(t, ctx, pins, index.PinKey("main", r16), pinned("pipeline."+p16))
|
|
|
|
|
// AC-I7b: a pipeline of main.15 that keeps avahi at main.16 ended cancelled pins main.16 and its base main.15 under the
|
|
|
|
|
// record, the mover's own entry being where it is kept.
|
|
|
|
|
again := p15 + ".again"
|
|
|
|
|
startedAgain, _ := json.Marshal(meshpipelinerunner.PipelineStarted{V: 1, Pipeline: again, Branch: "main", Source: 15, Revision: r15, Kept: []int64{r16}})
|
|
|
|
|
if _, err := js.Publish(ctx, meshpipelinerunner.SubjectPipelineStarted("main", strconv.FormatInt(r15, 10)), startedAgain); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
untilKey(t, ctx, pins, index.PinKey("main", r16), pinned("pipeline."+p16, "pipeline."+again))
|
|
|
|
|
endedPipeline(again, r15, meshpipelinerunner.PipelineEndedOutcomeCancelled, []meshpipelinerunner.MoverEnded{{Module: "avahi", Fingerprint: take16.Entries[0].Fingerprint,
|
|
|
|
|
Steps: []meshpipelinerunner.StepResult{{Step: meshpipelinerunner.StepResultStepUnit, Status: meshpipelinerunner.StepResultStatusRequired, Outcome: meshpipelinerunner.StepResultOutcomeCancelled}}}})
|
|
|
|
|
untilKey(t, ctx, pins, index.PinKey("main", r16), pinned("pipeline."+p16, failedRecord))
|
|
|
|
|
untilKey(t, ctx, pins, index.PinKey("main", r15), pinned("pipeline."+p16, failedRecord))
|
|
|
|
|
// Design 47 H2 §815: a source-only registration, kept under source.<owner>.<name>, watches its branch as any registration
|
|
|
|
|
// does, and a move of that branch by its repository, which holds no manifest, is taken in with no movers.
|
|
|
|
|
const hqCommit = "4444444444444444444444444444444444444444"
|
|
|
|
@@ -719,6 +791,17 @@ func TestIndexerWhole(t *testing.T) {
|
|
|
|
|
t.Errorf("the move of novox/hq on delta said %+v, want revision 2 with no movers", hq)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AC-I7c, H-A-756: avahi leaves main's registrations while a source-only registration is kept: the record is freed from every pin.
|
|
|
|
|
reg, _ = json.Marshal(meshcatalog.Registration{V: 1, Module: "avahi", Origin: "novox/mesh-catalog", Path: "modules/avahi", Branches: []string{"beta", "gamma"}})
|
|
|
|
|
if _, err := regs.Put(ctx, index.RegistrationKey("avahi"), reg); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if _, err := js.Publish(ctx, meshcatalog.SubjectRegistrationChanged, []byte(`{"module":"avahi"}`)); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
untilKey(t, ctx, pins, index.PinKey("main", r16), lacks(failedRecord))
|
|
|
|
|
untilKey(t, ctx, pins, index.PinKey("main", r15), lacks(failedRecord))
|
|
|
|
|
|
|
|
|
|
// Design 47 H2 H-A-708 (1), H-A-717 DQ-54: the start's phases are kept at start-phase of the state first-views, and the
|
|
|
|
|
// start's last phase ended is null.
|
|
|
|
|
untilKey(t, ctx, status, views.StartPhaseKey, func(v []byte) bool { return string(v) == "null" })
|
|
|
|
|