An ask put while the builder is down waited for nobody: the plain subscription heard only what came while it ran. The builder now pulls every waiting ask from the seat's one worker, takes it once by its id in its state taken (for ask-taken-bound), says ask-taken at the pull, sends in-progress while it builds and acknowledges once the step's end is said. Its publish to a registry seat is a kept call carrying the publish's ask id. The manifest declares taken and the kept-call pace and ask-taken-bound as runtime settings. Builds: design 47 H2 §775, §777, §820; H-A-381
92 lines
4.0 KiB
Go
92 lines
4.0 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/containerimageregistry"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/gopackageregistry"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/npmpackageregistry"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/ociartifactregistry"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/process"
|
|
|
|
"mesh-delivery-builder/internal/build"
|
|
"mesh-delivery-builder/internal/versions"
|
|
)
|
|
|
|
// TestRepublishSend: design 47 G §588, A-73: a publish again is the registry seat's publish with the digest and no parts; the
|
|
// four seats take one wire form, a call's fault or an answer that lacks parts is the holder's refusal in its words, and its
|
|
// setting is read from the file the manifest declares.
|
|
func TestRepublishSend(t *testing.T) {
|
|
p := versions.Publish{Seat: versions.SeatArtifacts, Kind: "bundle", Name: "m/prog", Version: "0.1.3", Digest: "sha256:aa", Fingerprint: "src2:m", Commit: "c", Transfer: "t"}
|
|
want, _ := json.Marshal(publishBody(p))
|
|
if strings.Contains(string(want), "parts") {
|
|
t.Errorf("the publish names parts: %s", want)
|
|
}
|
|
for name, v := range map[string]any{"container image": containerimageregistry.PublishInput{Digest: "sha256:aa"}, "oci": ociartifactregistry.PublishInput{Digest: "sha256:aa"},
|
|
"go": gopackageregistry.PublishInput{Digest: "sha256:aa"}, "npm": npmpackageregistry.PublishInput{Digest: "sha256:aa"}} {
|
|
var ref, got map[string]any
|
|
a, _ := json.Marshal(gopackageregistry.PublishInput{Digest: "sha256:aa"})
|
|
b, _ := json.Marshal(v)
|
|
_ = json.Unmarshal(a, &ref)
|
|
_ = json.Unmarshal(b, &got)
|
|
if len(ref) != len(got) {
|
|
t.Errorf("the %s seat's publish input is %s, the go seat's %s: one wire form is sent to all four", name, b, a)
|
|
}
|
|
}
|
|
var asked string
|
|
for name, c := range map[string]struct {
|
|
answer string
|
|
err error
|
|
want string
|
|
}{
|
|
"held": {`{"held":true,"transfer":"t"}`, nil, ""},
|
|
"lacks": {`{"lacks":["sha256:bb"],"transfer":"t"}`, nil, versions.NotStoredWords},
|
|
"a fault": {"", errors.New("no responders"), "no responders"},
|
|
"no sense": {`[`, nil, "no publish answer"},
|
|
} {
|
|
var id string
|
|
send := sendVia(func(ask process.KeptAsk, key string, body any) (json.RawMessage, error) {
|
|
asked, id = key, ask.ID
|
|
return json.RawMessage(c.answer), c.err
|
|
})
|
|
err := send(context.Background(), p)
|
|
// design 47 H2 §775: the publish carries its ask id, the same for the same publish
|
|
if asked != "seat:oci-artifact-registry.publish" || id != publishAskID(p) || strings.Contains(id, ".") || (c.want == "") != (err == nil) || (err != nil && !strings.Contains(err.Error(), c.want)) {
|
|
t.Errorf("%s: asked %q, error %v, want %q", name, asked, err, c.want)
|
|
}
|
|
}
|
|
// A send and its entry read honour the bound they are given (design 47 H H-A-290 (4)): a call still unanswered when it ends
|
|
// is said as not answered within it, and the send goes on.
|
|
release := make(chan struct{})
|
|
defer close(release)
|
|
called := make(chan struct{}, 2)
|
|
slow := func(string, any) (json.RawMessage, error) {
|
|
called <- struct{}{}
|
|
<-release
|
|
return json.RawMessage(`{}`), nil
|
|
}
|
|
for name, call := range map[string]func(context.Context) error{
|
|
"the publish": func(ctx context.Context) error {
|
|
return sendVia(func(_ process.KeptAsk, k string, b any) (json.RawMessage, error) { return slow(k, b) })(ctx, p)
|
|
},
|
|
"the entry": func(ctx context.Context) error { _, err := entryVia(slow)(ctx, "fp"); return err },
|
|
} {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
go func() { <-called; cancel() }()
|
|
if err := call(ctx); err == nil || !strings.Contains(err.Error(), "within its bound") {
|
|
t.Errorf("%s past its bound answered %v, want it not answered within its bound", name, err)
|
|
}
|
|
}
|
|
if _, _, err := build.NewRepublish("", "0.1.3", "why", "me", versionsNow()); err == nil {
|
|
t.Error("a version with no module is accepted")
|
|
}
|
|
}
|
|
|
|
func versionsNow() time.Time { return time.Unix(1, 0) }
|