assigner: an end said again is published under a message id naming the run that makes it say again, so the bus never drops it (A-470q)
A move names the moved run's ask, a take-up of a reader that ended the open run's, a drop the dropped run's; a first end keeps the ask's id. Test 108 reads the ends through a durable consumer, as the runner hears them. Builds: design 47 G §727; A-470d, A-470q.
This commit is contained in:
@@ -260,14 +260,14 @@ func (r *compositionRuns) endRunOf(key, ask, outcome, said string, verdict map[s
|
||||
|
||||
// readersOfOpen are the readers of every run with no `ended`, each with its ask's id once: what the assigner takes up again at
|
||||
// its start (§719), each reader's end said from the keys alone (A-468). A reader whose step said its end already, carried into a
|
||||
// rerun's run, is taken up only when it is marked `rerun` (A-470l, A-470m).
|
||||
func (r *compositionRuns) readersOfOpen() ([]meshwants.CompositionReader, error) {
|
||||
// rerun's run, is taken up only when it is marked `rerun` (A-470l, A-470m); each with the ask of the open run it is taken up from.
|
||||
func (r *compositionRuns) readersOfOpen() ([]openReader, error) {
|
||||
all, err := r.keys()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
var out []meshwants.CompositionReader
|
||||
var out []openReader
|
||||
for _, key := range all {
|
||||
if !isRunKey(key) {
|
||||
continue
|
||||
@@ -282,13 +282,19 @@ func (r *compositionRuns) readersOfOpen() ([]meshwants.CompositionReader, error)
|
||||
}
|
||||
if !seen[c.ID] {
|
||||
seen[c.ID] = true
|
||||
out = append(out, c)
|
||||
out = append(out, openReader{CompositionReader: c, ask: run.Ask})
|
||||
}
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// openReader is a reader taken up at the start and the ask of the open run it is taken up from.
|
||||
type openReader struct {
|
||||
meshwants.CompositionReader
|
||||
ask string
|
||||
}
|
||||
|
||||
// keysOf are the keys of the candidate's runs that the reader reads.
|
||||
func (r *compositionRuns) keysOf(candidate, id string) ([]string, error) {
|
||||
all, err := r.keys()
|
||||
@@ -355,6 +361,10 @@ func (c *compositionSteps) takeUp(ctx context.Context, r *compositionRuns) {
|
||||
}
|
||||
for _, reader := range readers {
|
||||
c.logf("the composition step %s of %s is taken up again by its runs (ask %s)", reader.Pipeline, reader.Module, reader.ID)
|
||||
go c.say1(ctx, reader.ID, stepRunOf(reader), c.resume)
|
||||
again := "" // a reader whose step said its end already says it again under the open run's ask (A-470q)
|
||||
if reader.Ended != nil {
|
||||
again = reader.ask
|
||||
}
|
||||
go c.say1(ctx, reader.ID, stepRunOf(reader.CompositionReader), c.resume, again)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -492,9 +492,13 @@ func TestARerunMovesEveryReaderThatDidNotPass(t *testing.T) {
|
||||
return m, true
|
||||
}
|
||||
ends := make(chan meshwants.StepEnded, 16)
|
||||
msgIDs := map[string]string{} // the message id of each step's latest end
|
||||
steps := &compositionSteps{node: "n1", now: time.Now, logf: t.Logf, run: s.r.run, resume: s.r.resume, ended: s.runs.stepEnded,
|
||||
say: func(event string, body any, _ string) error {
|
||||
say: func(event string, body any, msgID string) error {
|
||||
if e, ok := body.(meshwants.StepEnded); ok {
|
||||
mu.Lock()
|
||||
msgIDs[e.ID] = msgID
|
||||
mu.Unlock()
|
||||
ends <- e
|
||||
}
|
||||
return nil
|
||||
@@ -533,6 +537,12 @@ func TestARerunMovesEveryReaderThatDidNotPass(t *testing.T) {
|
||||
len(d.Shared) != 2 || d.Shared[1].Machine != "g14" || d.Shared[1].Ask == former || d.Shared[1].Ask != a.Shared[1].Ask {
|
||||
t.Fatalf("after the rerun: a %+v, d %+v", a, d)
|
||||
}
|
||||
mu.Lock()
|
||||
// A-470q: the first end keeps the ask's id; the end said again names the moved run's ask, so the bus does not drop it.
|
||||
if msgIDs["ask-a2"] != "ask-a2" || msgIDs["ask-d"] != "ask-d."+a.Shared[1].Ask || msgIDs["ask-b"] != "ask-b" {
|
||||
t.Errorf("the message ids of the ends: %v", msgIDs)
|
||||
}
|
||||
mu.Unlock()
|
||||
if s.puts != 3 {
|
||||
t.Errorf("%d run asks, want one more for the machine a did not pass", s.puts)
|
||||
}
|
||||
|
||||
+11
-3
@@ -104,16 +104,24 @@ func TestOneCompositionRunPerCandidateAndMachine(t *testing.T) {
|
||||
return map[string]any{}
|
||||
})
|
||||
respond("mesh.seat.mesh-hand-acts.call.hand-act.*", func(*nats.Msg) any { return map[string]any{"log": "hand-act-1"} })
|
||||
// The ends are read from the stream through a durable consumer, as the runner hears them: an end the bus drops as a
|
||||
// repeated message id is never heard (A-470q).
|
||||
ended := make(chan meshwants.StepEnded, 32)
|
||||
sub, err := nc.Subscribe("mesh.seat.mesh-wants.event.step-ended.n1", func(m *nats.Msg) {
|
||||
runner, err := b.js.CreateOrUpdateConsumer(b.ctx, "EVENTS", jetstream.ConsumerConfig{Durable: "runner-stand-in",
|
||||
FilterSubject: "mesh.seat.mesh-wants.event.step-ended.n1", AckPolicy: jetstream.AckExplicitPolicy, DeliverPolicy: jetstream.DeliverNewPolicy})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
heard, err := runner.Consume(func(m jetstream.Msg) {
|
||||
var e meshwants.StepEnded
|
||||
_ = json.Unmarshal(m.Data, &e)
|
||||
_ = json.Unmarshal(m.Data(), &e)
|
||||
_ = m.Ack()
|
||||
ended <- e
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = sub.Unsubscribe() })
|
||||
t.Cleanup(heard.Stop)
|
||||
subscribed(t, nc)
|
||||
|
||||
from := b.journal.mark()
|
||||
|
||||
@@ -85,7 +85,11 @@ func (c *compositionSteps) drop(r *compositionRuns, record func(meshhandactsclie
|
||||
}
|
||||
shared := []meshwants.Shared{{Machine: run.Machine, Run: key, Ask: run.Ask}}
|
||||
for _, reader := range run.Readers {
|
||||
c.sayEnd(reader.ID, stepRunOf(reader), nil, stepOutcome{Outcome: meshwants.StepEndedOutcomeCouldNotRun, Said: said, Shared: shared})
|
||||
again := "" // a reader whose step said its end already says it again under the dropped run's ask (A-470q)
|
||||
if reader.Ended != nil {
|
||||
again = run.Ask
|
||||
}
|
||||
c.sayEnd(reader.ID, stepRunOf(reader), nil, stepOutcome{Outcome: meshwants.StepEndedOutcomeCouldNotRun, Said: said, Shared: shared}, again)
|
||||
answer.Ended = append(answer.Ended, reader)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,13 +126,14 @@ func (c *compositionSteps) take(ctx context.Context, id string, data []byte) boo
|
||||
c.logf("a step ask that is no composition step with an id is left: %v", err)
|
||||
return false
|
||||
}
|
||||
go c.say1(ctx, id, run, c.run)
|
||||
go c.say1(ctx, id, run, c.run, "")
|
||||
return true
|
||||
}
|
||||
|
||||
// say1 runs one step with how and says its end, naming in `shared` the runs it read (§723). A step whose wait was ended by its
|
||||
// pipeline's supersede or cancel (leave) says nothing: the runner ended it already.
|
||||
func (c *compositionSteps) say1(ctx context.Context, id string, run meshwants.StepRun, how func(context.Context, string, meshwants.StepRun) stepOutcome) {
|
||||
// say1 runs one step with how and says its end, naming in `shared` the runs it read (§723); again is, for an end said again, the
|
||||
// ask of the run whose end makes it say again (sayEnd). A step whose wait was ended by its pipeline's supersede or cancel (leave)
|
||||
// says nothing: the runner ended it already.
|
||||
func (c *compositionSteps) say1(ctx context.Context, id string, run meshwants.StepRun, how func(context.Context, string, meshwants.StepRun) stepOutcome, again string) {
|
||||
started := c.now().UTC()
|
||||
ctx, stopWait := context.WithCancel(ctx)
|
||||
c.mu.Lock()
|
||||
@@ -160,12 +161,13 @@ func (c *compositionSteps) say1(ctx context.Context, id string, run meshwants.St
|
||||
c.logf("the composition step %s of %s says no end: its wait ended (%v)", id, run.Pipeline, context.Cause(ctx))
|
||||
return
|
||||
}
|
||||
c.sayEnd(id, run, &started, o)
|
||||
c.sayEnd(id, run, &started, o, again)
|
||||
}
|
||||
|
||||
// sayEnd says the end of the step asked under id as the seat's step-ended.<node>, its id the ask's; once said, its time is
|
||||
// written as its reader's `ended` (A-470m).
|
||||
func (c *compositionSteps) sayEnd(id string, run meshwants.StepRun, started *time.Time, o stepOutcome) {
|
||||
// written as its reader's `ended` (A-470m). Its first end's message id is the ask's id; an end said again is published under
|
||||
// `<ask id>.<again>`, again the ask of the run whose end makes it say again, so the bus's deduplication never drops it (A-470q).
|
||||
func (c *compositionSteps) sayEnd(id string, run meshwants.StepRun, started *time.Time, o stepOutcome, again string) {
|
||||
ended := c.now().UTC()
|
||||
if started == nil {
|
||||
started = &ended
|
||||
@@ -173,7 +175,11 @@ func (c *compositionSteps) sayEnd(id string, run meshwants.StepRun, started *tim
|
||||
end := meshwants.StepEnded{V: 1, ID: id, Pipeline: run.Pipeline, Step: meshwants.StepEndedStepComposition, Module: run.Module,
|
||||
Commit: run.Commit, Fingerprint: run.Fingerprint, Node: c.node, Outcome: o.Outcome, Said: o.Said, Warnings: o.Warnings,
|
||||
Rerun: run.Rerun, By: run.By, Started: started, Ended: &ended, Shared: o.Shared}
|
||||
if err := c.say(meshwants.EventStepEnded+"."+c.node, end, id); err != nil {
|
||||
msgID := id
|
||||
if again != "" {
|
||||
msgID = id + "." + again
|
||||
}
|
||||
if err := c.say(meshwants.EventStepEnded+"."+c.node, end, msgID); err != nil {
|
||||
c.logf("saying the end of the composition step %s: %v", id, err)
|
||||
return
|
||||
}
|
||||
@@ -191,7 +197,7 @@ func (c *compositionSteps) move(ctx context.Context) func(run meshwants.Composit
|
||||
continue
|
||||
}
|
||||
c.logf("the composition step %s of %s moves with the composition run of %s (ask %s)", reader.ID, reader.Pipeline, run.Machine, run.Ask)
|
||||
go c.say1(ctx, reader.ID, stepRunOf(reader), c.resume)
|
||||
go c.say1(ctx, reader.ID, stepRunOf(reader), c.resume, run.Ask) // said again under the moved run's ask (A-470q)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user