The work queue publishes is declared in the manifest's old streams section (retention work-queue, duplicates 24 h, max-deliveries 10, 64 MiB, 7 days), the module's own stream consumed on the module's account, so the bus binding asked of the broker seat goes; the consumers per holder and class are still made at run time. The seat mesh-builds gains the read verb publish-queue, served by the builder from its own stream (counts per holder and class, oldest and newest, a list capped at 50, capped past 4,000 items read), and builder_publish_queue asks it in place of the runtime's stream and work-queue reads. Two whole tests of a gone artifact are folded into one, so the builder's integration count stays at 18 with the publishes whole test. Builds: design 47 H2 §793, §819, §820; H-A-440 (1), H-A-446 (2), H-A-454 and its addendum
115 lines
6.2 KiB
Go
115 lines
6.2 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
|
|
"mesh-delivery-builder/internal/build"
|
|
|
|
"mesh-delivery-builder/internal/versions"
|
|
)
|
|
|
|
// TestAStateIsReadInOnePage: design 47 H H-A-292, H-A-293 — builder_publish_queue reads each of its own states in one page and
|
|
// never asks a second: a state past the page answers that page with More and the state's size from its info; one the page holds
|
|
// answers whole without reading the info.
|
|
func TestAStateIsReadInOnePage(t *testing.T) {
|
|
for _, c := range []struct {
|
|
name string
|
|
next string
|
|
}{{"past one page", "k1"}, {"held by one page", ""}} {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
var asked []string
|
|
infos := 0
|
|
page := func(after string, maxBytes int, budget time.Duration) (stdio.StatePage, error) {
|
|
asked = append(asked, after)
|
|
if after != "" {
|
|
return stdio.StatePage{Entries: []stdio.StateEntry{{Key: "k2", Value: json.RawMessage(`2`)}}}, nil
|
|
}
|
|
return stdio.StatePage{Entries: []stdio.StateEntry{{Key: "k1", Value: json.RawMessage(`1`)}}, Next: c.next}, nil
|
|
}
|
|
info := func() (*stdio.StateInfo, error) { infos++; return &stdio.StateInfo{Keys: 2, Bytes: 640}, nil }
|
|
pg, err := onePage(page, info)
|
|
more := c.next != ""
|
|
if err != nil || len(asked) != 1 || len(pg.Values) != 1 || pg.More != more || (more && (pg.Keys != 2 || pg.Bytes != 640 || infos != 1)) || (!more && infos != 0) {
|
|
t.Errorf("asked the pages after %q, read %v, more %v, size %d keys %d bytes, info read %d times (%v): want one page only, its rest said with the state's size", asked, pg.Values, pg.More, pg.Keys, pg.Bytes, infos, err)
|
|
}
|
|
})
|
|
}
|
|
unsupported := func(string, int, time.Duration) (stdio.StatePage, error) {
|
|
return stdio.StatePage{}, errors.ErrUnsupported
|
|
}
|
|
if _, err := onePage(unsupported, nil); !errors.Is(err, errors.ErrUnsupported) {
|
|
t.Errorf("a runtime with no pages answered %v, want ErrUnsupported so the reader reads key by key", err)
|
|
}
|
|
// Design 47 H2 §794, H-A-435: builder_health reads the state consumers; a consumer whose oldest unacknowledged message waits
|
|
// six minutes is named, one within five minutes is not.
|
|
t.Run("builder_health names a consumer behind by five minutes", func(t *testing.T) {
|
|
now := time.Unix(10000, 0)
|
|
facts := map[string]json.RawMessage{
|
|
"builder-events": json.RawMessage(`{"stream":"EVENTS","name":"builder-events","pending":40,"oldest-unacknowledged":"` + now.Add(-6*time.Minute).UTC().Format(time.RFC3339) + `"}`),
|
|
"builder-kept": json.RawMessage(`{"stream":"K","name":"builder-kept","oldest-unacknowledged":"` + now.Add(-time.Minute).UTC().Format(time.RFC3339) + `"}`)}
|
|
r := versions.Reader{Keys: func() ([]string, error) { return []string{"builder-kept", "builder-events"}, nil },
|
|
Get: func(k string) (json.RawMessage, bool, error) { v, ok := facts[k]; return v, ok, nil }}
|
|
a := builderHealth(r, now)
|
|
if a.Healthy || a.Why != "The builder's consumers behind by 5m0s or more: builder-events (its oldest unacknowledged message waits 6m0s, 40 more not yet given)." {
|
|
t.Errorf("health = %+v, want unhealthy naming builder-events alone", a)
|
|
}
|
|
if a := builderHealth(r, now.Add(-2*time.Minute)); !a.Healthy {
|
|
t.Errorf("health four minutes in = %+v, want healthy", a)
|
|
}
|
|
})
|
|
// Design 47 H2 §793, H-A-454: builder_publish_queue asks the seat mesh-builds' verb publish-queue, which the builder serves from
|
|
// its own stream, and answers its counts, list and cap with the states beside them; builder_publish_drop and
|
|
// builder_publish_first record the hand act first, then write their reasks value.
|
|
t.Run("the queue is the builder's verb publish-queue", func(t *testing.T) {
|
|
var asked []string
|
|
ask := func(key string, body any) (json.RawMessage, error) {
|
|
in := body.(meshbuilds.PublishQueueInput)
|
|
asked = append(asked, key+" "+in.Module)
|
|
return json.Marshal(meshbuilds.PublishQueueAnswer{Total: 9000, Listed: 1, Capped: true, ItemsRead: 4000, QueueItems: 9000, QueueBytes: 4096,
|
|
Counts: []meshbuilds.PublishQueueAnswerCountsItem{{Holder: "oci", Class: versions.PublishClassStart, Count: 4000}},
|
|
Queue: []meshbuilds.PublishQueueAnswerQueueItem{{Holder: "oci", Module: "m", Version: "0.1.0", Class: versions.PublishClassStart}}})
|
|
}
|
|
none := versions.Reader{Keys: func() ([]string, error) { return nil, nil }}
|
|
tools := republishTools(publishQueueVia(ask), none, none, nil, time.Now, meshhandactsclient.Recorder{})
|
|
raw, err := tools[1].Run(map[string]any{"module": "m"})
|
|
a, _ := raw.(versions.Queued)
|
|
if err != nil || fmt.Sprint(asked) != "[seat:mesh-builds.publish-queue m]" || a.Total != 9000 || len(a.Queue) != 1 || a.Queue[0].Module != "m" ||
|
|
len(a.Counts) != 1 || !a.Capped || len(a.Read) != 1 || a.Read[0].KeysRead != 4000 || a.Read[0].StateKeys != 9000 {
|
|
t.Errorf("%s asked %v, answered %+v (%v): want the verb asked with the module, its answer carried with its cap", tools[1].Name, asked, a, err)
|
|
}
|
|
})
|
|
t.Run("drop and first record the hand act, then ask the builder", func(t *testing.T) {
|
|
var order []string
|
|
ask := func(key string, value []byte) (json.RawMessage, error) {
|
|
order = append(order, "ask "+key)
|
|
r, _ := build.DecodeReAsk(value)
|
|
r.Answer = "done"
|
|
return json.Marshal(r)
|
|
}
|
|
acts := meshhandactsclient.Recorder{Ask: func(key string, body any) (json.RawMessage, error) {
|
|
order = append(order, "record")
|
|
return json.RawMessage(`{"id":"h1"}`), nil
|
|
}}
|
|
tools := publishActTools(ask, func() time.Time { return time.Unix(5, 0) }, acts)
|
|
for _, tool := range tools {
|
|
if _, err := tool.Run(map[string]any{"module": "m", "version": "0.1.2", "why": "a test"}); err != nil {
|
|
t.Fatalf("%s: %v", tool.Name, err)
|
|
}
|
|
}
|
|
if len(tools) != 2 || fmt.Sprint(order) != "[record ask publish-drop.5000000000 record ask publish-first.5000000000]" {
|
|
t.Errorf("tools %d, order %v: want each hand act recorded before its reasks value", len(tools), order)
|
|
}
|
|
if _, err := tools[0].Run(map[string]any{"module": "m", "why": "no version"}); err == nil {
|
|
t.Error("a drop naming no version is not refused")
|
|
}
|
|
})
|
|
}
|