The seat gains the events filling, full and room; at each step's end and each start the runner reads the fill of pipelines, step-outputs, kept and step-log against their caps, says filling past 80 %, full at the cap and room below 70 %, and a start while a store is full is refused, said in the journal and heard again by the bus. Builds: design 47 G §366, §181 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
53 lines
1.8 KiB
Go
53 lines
1.8 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
|
)
|
|
|
|
// A store past 80 % of its cap says `filling` once, at its cap `full` and refuses a start, said; below 70 % it says `room` and
|
|
// the start goes (design 47 G §366).
|
|
func TestAStoreFillingIsSaidAndAFullStoreRefusesAStart(t *testing.T) {
|
|
bytes := int64(10)
|
|
var said []string
|
|
var journal []string
|
|
f := &Fills{
|
|
Read: func() ([]seat.Fill, error) { return []seat.Fill{{Store: "pipelines", Bytes: bytes, Cap: 100}}, nil },
|
|
Say: func(event string, fl seat.Fill) error { said = append(said, event+":"+fl.Store); return nil },
|
|
Logf: func(format string, a ...any) { journal = append(journal, format) }}
|
|
steps := []struct {
|
|
bytes int64
|
|
say string
|
|
}{{10, "room:pipelines"}, {75, ""}, {81, "filling:pipelines"}, {85, ""}, {100, "full:pipelines"}, {75, ""}, {69, "room:pipelines"}}
|
|
for _, st := range steps {
|
|
bytes, said = st.bytes, nil
|
|
f.Check()
|
|
got := ""
|
|
if len(said) == 1 {
|
|
got = said[0]
|
|
}
|
|
if got != st.say || len(said) > 1 {
|
|
t.Fatalf("at %d of 100 bytes the runner said %v, want %q", st.bytes, said, st.say)
|
|
}
|
|
}
|
|
bytes = 100
|
|
s := &Starter{Pipelines: failingCreate{}, Fills: f, Say: func(string, any) error { return nil }}
|
|
ok, err := s.Start(Begin{Branch: "main", Source: 1, Module: "app"})
|
|
if ok || !errors.Is(err, ErrFull) {
|
|
t.Fatalf("a start with pipelines full: %v, %v; want it refused with ErrFull", ok, err)
|
|
}
|
|
if len(journal) == 0 {
|
|
t.Error("the refused start is not said in the journal")
|
|
}
|
|
bytes = 10
|
|
if ok, err := s.Start(Begin{Branch: "main", Source: 1, Module: "app"}); !ok || err != nil {
|
|
t.Fatalf("a start on room: %v, %v", ok, err)
|
|
}
|
|
}
|
|
|
|
type failingCreate struct{}
|
|
|
|
func (failingCreate) Create(string, []byte) error { return nil }
|