Files
mesh-controller/cmd/mesh-controller/sweep_keeps_fresh_test.go
T
jschoubben 0741880d31
mesh/delivery delivered
mesh/check checking 0741880d3137 on 760351b4ae1b
Keep a fresh build's archives from the controller's own sweep (issue 1933)
A sweep read what it keeps before what was ever recorded, so a take-in's
build recorded between the two reads, by a concurrent take-in off the
plans' hold, was eligible and let go of seconds after the take-in read
it; a new module's build is unkept until it is registered. Now the sweep
reads the records first and keeps what a build recorded within the hour
or an open plan names, and names every reference it lets go of; a take-in
holds every artifact in the store before recording, failing on one the
store lacks; and RecordBuild clears artifact_collected as RecordMirrored
does.
2026-10-24 02:44:20 +02:00

68 lines
2.9 KiB
Go

package main
import (
"bytes"
"context"
"errors"
"strings"
"testing"
sdkdelivery "git.novox.be/novox/mesh-sdk/go/delivery"
"github.com/novox/mesh-controller/internal/artifacts"
)
// 1933/AC2: a take-in holds every artifact of the key in the artifact store before anything is recorded, and an archive
// the store does not hold fails it, "not in the artifact store", with no build to record: on 2026-10-24 00:37 the
// indexer's program blob was missing, the take-in registered it anyway and novox failed every apply on its 404.
func TestATakeInHoldsEveryArtifactAndFailsOnOneTheStoreLacks(t *testing.T) {
program := "artifact-store://x/tools/blobs/" + shaOf("t")
image := "artifact-store://x/img@" + shaOf("i")
keys, trunk := aKeyOf(tsBundle, 3,
sdkdelivery.BuiltArtifact{Name: "tools", Kind: "bundle", Digest: shaOf("t"), Reference: program},
sdkdelivery.BuiltArtifact{Name: "img", Kind: "image", Digest: shaOf("i"), Reference: image})
take := keyTake{Module: "x", Trunk: trunk}
var held []string
holds := func(_ context.Context, reference string) error { held = append(held, reference); return nil }
if _, _, err := buildOfKey(t.Context(), keys, take, keyContext{hold: holds}); err != nil {
t.Fatal(err)
}
if strings.Join(held, " ") != program+" "+image {
t.Errorf("the take-in held %v; want both of the key's artifacts", held)
}
lacks := func(_ context.Context, reference string) error {
if reference == program {
return artifacts.Gone
}
return nil
}
kept, _, err := buildOfKey(t.Context(), keys, take, keyContext{hold: lacks})
if err == nil || errors.Is(err, errKeyWaits) || !strings.Contains(err.Error(), "not in the artifact store") ||
!strings.Contains(err.Error(), program) {
t.Errorf("a take-in whose program archive the store lacks: %v; want a failure naming it, not in the artifact store", err)
}
if kept.ID != "" || len(kept.Made) > 0 {
t.Errorf("a take-in that failed made a build to record: %s %v", kept.ID, kept.Made)
}
unreachable := func(context.Context, string) error { return errors.New("connection refused") }
if _, _, err := buildOfKey(t.Context(), keys, take, keyContext{hold: unreachable}); !errors.Is(err, errKeyWaits) {
t.Errorf("a store that cannot be asked: %v; want a wait", err)
}
}
// 1933/AC1: the sweep after a build names every reference it let go of, not only how many, so a let-go that broke a
// machine is read from the controller's log.
func TestTheSweepSaysEveryReferenceItLetGoOf(t *testing.T) {
var out bytes.Buffer
sayCollected(&out, sweepResult{Held: true, LetGo: []string{
"artifact-store://route-proxy/files/blobs/sha256:58bd41dc", "artifact-store://old/app@sha256:01"}})
for _, reference := range []string{"artifact-store://route-proxy/files/blobs/sha256:58bd41dc",
"artifact-store://old/app@sha256:01"} {
if !strings.Contains(out.String(), reference) {
t.Errorf("the sweep's words do not name %s:\n%s", reference, out.String())
}
}
}