diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/floor_integration_test.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/floor_integration_test.go index c3c742dc..f64f4522 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/floor_integration_test.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/floor_integration_test.go @@ -15,6 +15,7 @@ import ( "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" + "git.novox.be/novox/mesh-sdk/go/busretry" "mesh-delivery-indexer/internal/index" ) @@ -22,9 +23,11 @@ import ( // TestIndexerFillsTheFloorOfAModuleWithTags (design 47 G §412 as A-490c to A-490h amend it): the whole indexer on a real bus, the // seat git and the package holders stood in. A module of the trunk with a Go package and no version in `versions` stays unfilled // while the forge does not answer, and is filled from the highest of its tags and the holder's versions once the forge answers, -// on the growing pause (5 s) with no restart and no catalog revision. The finding after five minutes is in the unit tests -// (the five minutes are not waited for here); the kept call asks again by itself, with no restart and no new revision. +// with no restart and no catalog revision: the kept call gives up after its bound (one second here, so that it is spent before the +// forge answers) and the fill asks it again at once (A-490i, ADR 0668 §3). The finding after five minutes is in the unit tests (the +// five minutes are not waited for here). func TestIndexerFillsTheFloorOfAModuleWithTags(t *testing.T) { + t.Cleanup(busretry.Waits(time.Second, 50*time.Millisecond, 200*time.Millisecond)) // the form gives up after one second const pkg = "git.novox.be/novox/mesh-delivery/modules/" + testIndexer var serveTags func() var prefix atomic.Value @@ -85,7 +88,19 @@ func TestIndexerFillsTheFloorOfAModuleWithTags(t *testing.T) { if err != nil { t.Fatal(err) } - time.Sleep(2 * time.Second) // the forge is asked at the start and does not answer: nothing is filled + // the forge is asked at the start and does not answer: the form gives up and the module's clock is kept in the state heard + heard, err := js.KeyValue(ctx, index.Bucket(testIndexer, index.HeardState)) + if err != nil { + t.Fatal(err) + } + for deadline := time.Now().Add(30 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) { + if _, err := heard.Get(ctx, index.FloorSinceKey(testIndexer)); err == nil { + break + } + } + if _, err := heard.Get(ctx, index.FloorSinceKey(testIndexer)); err != nil { + t.Fatalf("the unanswered floor read of the module is not kept within 30 s: %v", err) + } if keys, _ := versions.Keys(ctx); len(keys) != 0 { t.Fatalf("versions holds %v while the forge does not answer, want nothing", keys) } diff --git a/modules/mesh-delivery-indexer/internal/index/tag_floor.go b/modules/mesh-delivery-indexer/internal/index/tag_floor.go index 929d93ea..b7e69553 100644 --- a/modules/mesh-delivery-indexer/internal/index/tag_floor.go +++ b/modules/mesh-delivery-indexer/internal/index/tag_floor.go @@ -98,6 +98,14 @@ func (ix *Indexer) FillFloor(ctx context.Context, module string, src FloorSource return nil } defer ix.floors.Delete(module) + // Whatever way the fill ends but by the end of ctx, the module's call is no longer unanswered: it answered, or it left the + // trunk, or a release gave it a version, or the callee answered with a failure (ADR 0668 §3: the finding clears when the call + // is answered), and FloorModules never picks the module again to clear it. + defer func() { + if ctx.Err() == nil { + ix.floorAnswered(ctx, module) + } + }() for ctx.Err() == nil { entry, found, err := ix.newestEntry(ctx, module) if err != nil || !found { @@ -106,15 +114,15 @@ func (ix *Indexer) FillFloor(ctx context.Context, module string, src FloorSource if have, err := ModuleVersions(ctx, ix.Versions, module); err != nil || len(have) > 0 { return err } + first := ix.now() // the clock of the module's unanswered call starts at its try, not when the form gives up top, err := ix.floorOf(ctx, entry, src) if err == nil { - ix.floorAnswered(ctx, module) return ix.keepFloor(ctx, module, top) } if !busretry.Undelivered(err) && !busretry.TimedOut(err) { - return err + return err // answered with a failure: the fill ends, said by the caller } - ix.floorUnanswered(ctx, module, err) + ix.floorUnanswered(ctx, module, first, err) } return ctx.Err() } @@ -185,10 +193,15 @@ func (ix *Indexer) keepFloor(ctx context.Context, module, top string) error { func floorKey(module string) string { return FloorCall + "." + module } +// FloorSinceKey is the key of the state heard that holds when a module's floor call was first unanswered. +func FloorSinceKey(module string) string { return floorSinceKey(module) } + +func floorSinceKey(module string) string { return "call-since." + keys.EscapeName(floorKey(module)) } + // floorUnanswered writes call-unanswered once the module's floor read is unanswered five minutes (the time kept in the own state). -func (ix *Indexer) floorUnanswered(ctx context.Context, module string, cause error) { +func (ix *Indexer) floorUnanswered(ctx context.Context, module string, first time.Time, cause error) { now := ix.now() - since := ix.unansweredSince(ctx, "call-since."+keys.EscapeName(floorKey(module)), now) + since := ix.unansweredSince(ctx, floorSinceKey(module), first) if ix.Findings == nil || now.Sub(since) < mcc.CallUnansweredAfter { return } @@ -204,7 +217,7 @@ func (ix *Indexer) floorUnanswered(ctx context.Context, module string, cause err } func (ix *Indexer) floorAnswered(ctx context.Context, module string) { - ix.answered(ctx, "call-since."+keys.EscapeName(floorKey(module))) + ix.answered(ctx, floorSinceKey(module)) if ix.Findings != nil { if err := ix.clearFinding(ctx, mcc.ScopeCall, floorKey(module), mcc.KindCallUnanswered, "the floor's reads answer"); err != nil { ix.logf("floor: the finding %s is not cleared: %v", floorKey(module), err) diff --git a/modules/mesh-delivery-indexer/internal/index/versions_test.go b/modules/mesh-delivery-indexer/internal/index/versions_test.go index 495cfb46..9a854d85 100644 --- a/modules/mesh-delivery-indexer/internal/index/versions_test.go +++ b/modules/mesh-delivery-indexer/internal/index/versions_test.go @@ -658,3 +658,63 @@ func TestAFloorEntryIsReplacedByThePublishHeardAtItsVersion(t *testing.T) { t.Fatalf("the floor 0.3.0 and its publish: versions %+v, version-released said %d", v, len(said)) } } + +// ADR 0668 §3, design 47 G A-490i: the finding call-unanswered of a module's floor clears, with its call-since key, on every way the +// fill ends but the end of its context: a release gave the module a version, the module left the trunk, or the callee answered with a +// failure (FloorModules never picks the module again to clear it). +func TestTheFloorFindingClearsOnEveryExitOfTheFill(t *testing.T) { + for name, exit := range map[string]func(ctx context.Context, t *testing.T, ix *Indexer) error{ + "a release gave it a version": func(ctx context.Context, t *testing.T, ix *Indexer) error { + if err := ix.Versions.Create(ctx, meshcatalog.VersionsByModuleVersionKey("mod", "0.5.0"), []byte(`{"v":1,"module":"mod","version":"0.5.0","artifacts":[{"artifact":"mod:go"}]}`)); err != nil { + t.Fatal(err) + } + return errors.New("no responders available for request") + }, + "it left the trunk": func(ctx context.Context, t *testing.T, ix *Indexer) error { + rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 2, Kind: "trunk"}, map[string]meshcatalog.CatalogEntry{}) + if err != nil { + t.Fatal(err) + } + if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil { + t.Fatal(err) + } + return errors.New("no responders available for request") + }, + "the callee answered with a failure": func(context.Context, *testing.T, *Indexer) error { return errors.New("the forge refused") }, + } { + t.Run(name, func(t *testing.T) { + ctx := context.Background() + now := time.Date(2026, 11, 19, 17, 0, 0, 0, time.UTC) + w := newFindings() + ix := &Indexer{Module: testSelf, Versions: newMem(), Heard: newMem(), Findings: w, Revisions: newMemObjects(1 << 20), Now: func() time.Time { return now }} + entries := map[string]meshcatalog.CatalogEntry{"mod": {Module: "mod", Repository: "novox/mod", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{ + {Ref: "mod:go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/mod"}}}}} + rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 1, Kind: "trunk"}, entries) + if err != nil { + t.Fatal(err) + } + if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil { + t.Fatal(err) + } + tries := 0 + read := func(context.Context, string, string) ([]string, error) { + tries++ + now = now.Add(time.Minute) + if tries <= 6 { + return nil, errors.New("no responders available for request") + } + if len(w.Held()) != 1 { + t.Fatalf("the finding is not written before the exit: %+v", w.Held()) + } + return nil, exit(ctx, t, ix) + } + _ = ix.FillFloor(ctx, "mod", FloorSources{Tags: read}) + if h := w.Held(); len(h) != 0 { + t.Errorf("the finding stands after the fill ended: %+v", h) + } + if _, _, found, _ := ix.Heard.Get(ctx, FloorSinceKey("mod")); found { + t.Error("the call-since key stands after the fill ended") + } + }) + } +}