G1: the Go build module says a done build's import set as imports-reported (issue 721)
The ask's steps gain SayImports, the shared step runner's say of the seat event imports-reported on this node's subject of node-build-go, published with the module's SayEvent as its other events are, so the indexer hears each module's import set from the build that read it. Builds: design 47 H2 H-A-517, H-A-518, H-A-532 DQ-2, DMC-2
This commit is contained in:
@@ -51,10 +51,22 @@ func (m *Module) askSteps(steps []StepTool) steprun.AskSteps {
|
||||
Lint: m.lintStep,
|
||||
Node: m.Node,
|
||||
SayStep: m.sayStep(),
|
||||
Outputs: m.outputs(),
|
||||
// A build that read its imports says them as the seat's imports-reported on this node (design 47 H2 H-A-517,
|
||||
// H-A-532 DQ-2, DMC-2), published as the puller's other events are (SayEvent; nil says none, a test's).
|
||||
SayImports: m.sayImports(),
|
||||
Outputs: m.outputs(),
|
||||
}
|
||||
}
|
||||
|
||||
// sayImports says a build's import set on this node's subject of the seat (design 47 H2 H-A-517, H-A-532 DQ-2), with
|
||||
// SayEvent; nil when the module says no event.
|
||||
func (m *Module) sayImports() func(seat.ImportsReported) error {
|
||||
if m.SayEvent == nil {
|
||||
return nil
|
||||
}
|
||||
return steprun.SayImportsOn(sdkstep.AskGo, m.Node, m.SayEvent)
|
||||
}
|
||||
|
||||
// outputs are the outputs objects a test step keeps its run's output in and the verb output reads (design 47 H2 §791,
|
||||
// §820): Outputs when a test sets it, else the module's own objects store on the bus.
|
||||
func (m *Module) outputs() steprun.OutputObjects {
|
||||
|
||||
@@ -4,6 +4,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
|
||||
"git.novox.be/novox/mesh-sdk/go/testbus"
|
||||
@@ -30,6 +32,9 @@ const checkCommit = "89abcdef0123456789abcdef0123456789abcdef"
|
||||
// **The order is read from the record.** At capacity 1 the puller starts the check the instant the delivery ask's step
|
||||
// ends, well before any poll, so "the check key holds a state" is true on correct behaviour (issue 1887). The test
|
||||
// waits for both asks to end and compares the step records' own Started and Ended times, and the fetch order by commit.
|
||||
//
|
||||
// G1/AC2 (design 47 H2 H-A-517, H-A-532 DQ-2): each build that read its imports says imports-reported, and the
|
||||
// delivery ask's is on the bus, on the seat's subject of the node.
|
||||
func TestTheModuleTakesADeliveryAskBeforeAnEarlierCheck(t *testing.T) {
|
||||
nc, err := nats.Connect(testbus.URL(t))
|
||||
if err != nil {
|
||||
@@ -64,9 +69,24 @@ func TestTheModuleTakesADeliveryAskBeforeAnEarlierCheck(t *testing.T) {
|
||||
states := newStates()
|
||||
m := moduleWith(states, "go1.26.0")
|
||||
m.Capacity = func() int { return 1 }
|
||||
reported := make(chan *nats.Msg, 4)
|
||||
sub, err := nc.ChanSubscribe(seat.SubjectImportsReportedAll, reported)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = sub.Unsubscribe() }()
|
||||
m.SayEvent = func(subject string, body any, _ string) error {
|
||||
raw, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nc.Publish(subject, raw)
|
||||
}
|
||||
var mu sync.Mutex
|
||||
var order []string
|
||||
steps := fakeSteps(new([]string))
|
||||
steps := append(fakeSteps(new([]string)), StepTool{Name: ImportsTool, Run: func(context.Context, map[string]any) (any, error) {
|
||||
return ImportsResult{Imports: []string{"git.novox.be/novox/mesh-sdk/go"}}, nil
|
||||
}})
|
||||
for i := range steps {
|
||||
if steps[i].Name == "build_go_fetch" {
|
||||
run := steps[i].Run
|
||||
@@ -113,8 +133,26 @@ func TestTheModuleTakesADeliveryAskBeforeAnEarlierCheck(t *testing.T) {
|
||||
t.Fatalf("the check ask started at %v, before the delivery ask ended at %v at capacity 1", checkStarted, deliveryEnded)
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if len(order) != 2 || order[0] != askCommit || order[1] != checkCommit {
|
||||
t.Fatalf("fetched %v, want the delivery ask's commit %s first, then the check's %s", order, askCommit, checkCommit)
|
||||
}
|
||||
mu.Unlock()
|
||||
for timeout := time.After(10 * time.Second); ; {
|
||||
select {
|
||||
case msg := <-reported:
|
||||
var r seat.ImportsReported
|
||||
if err := json.Unmarshal(msg.Data, &r); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r.Commit != askCommit {
|
||||
continue
|
||||
}
|
||||
if msg.Subject != seat.SubjectImportsReported("ace") || r.Module != "mesh-delivery-view" || len(r.Imports) != 1 {
|
||||
t.Fatalf("imports-reported on %s: %+v", msg.Subject, r)
|
||||
}
|
||||
return
|
||||
case <-timeout:
|
||||
t.Fatal("the delivery ask's imports-reported never reached the bus")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
|
||||
)
|
||||
@@ -28,3 +31,47 @@ func TestPullerSaysTheSeatsEventsOnItsNodesSubject(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// G1/AC1 (design 47 H2 H-A-517, H-A-532 DQ-2): a build ask of a module with Go bundles that ends done says one
|
||||
// imports-reported on the seat's subject of the node, naming the module, the fingerprint, the commit and the imports
|
||||
// the imports step read.
|
||||
func TestADoneBuildSaysItsImportSetOnTheNodesSubject(t *testing.T) {
|
||||
type said struct {
|
||||
subject, id string
|
||||
body seat.ImportsReported
|
||||
}
|
||||
var events []said
|
||||
m := moduleWith(newStates(), "go1.26.0")
|
||||
m.SayEvent = func(subject string, body any, id string) error {
|
||||
r, ok := body.(seat.ImportsReported)
|
||||
if !ok {
|
||||
raw, _ := json.Marshal(body)
|
||||
t.Fatalf("said %s with %T: %s", subject, body, raw)
|
||||
}
|
||||
events = append(events, said{subject, id, r})
|
||||
return nil
|
||||
}
|
||||
imports := []string{"git.novox.be/novox/mesh-sdk/go", "git.novox.be/novox/mesh-sdk/go/busstate"}
|
||||
steps := append(fakeSteps(new([]string)), StepTool{Name: ImportsTool, Run: func(context.Context, map[string]any) (any, error) {
|
||||
return ImportsResult{Imports: imports}, nil
|
||||
}})
|
||||
a := deliveryAsk()
|
||||
a.Build.Fp = "src2:0123"
|
||||
if _, err := steprun.RunAsk(context.Background(), m.askSteps(steps), a); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(events) != 1 {
|
||||
t.Fatalf("said %d imports-reported, want 1: %+v", len(events), events)
|
||||
}
|
||||
e := events[0]
|
||||
if e.subject != seat.SubjectImportsReported("ace") {
|
||||
t.Errorf("said on %s, want %s", e.subject, seat.SubjectImportsReported("ace"))
|
||||
}
|
||||
if e.id != "imports-reported.mesh-delivery-view.src2:0123" {
|
||||
t.Errorf("id %s", e.id)
|
||||
}
|
||||
if e.body.Node != "ace" || e.body.Module != "mesh-delivery-view" || e.body.Fingerprint != "src2:0123" || e.body.Commit != askCommit ||
|
||||
len(e.body.Imports) != 2 || e.body.Imports[0] != imports[0] || e.body.Imports[1] != imports[1] {
|
||||
t.Errorf("said %+v", e.body)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user