Files
mesh-delivery/modules/mesh-delivery-sdk/steprun/pull_poison_test.go
T
jschoubben 78adc23d70 steprun: only runs that started count toward poison; an ended ask is acknowledged and its poison end said (A-489)
The bus counts an ask given back before it ran as a delivery, so four asks were ended 'poison' having never run. Puller.Prior
(PriorRuns) counts the runs the step key says started. A poisoned pipeline step now says its step-ended, so the runner stops
waiting. refuseUnread, refuseAsker and the poison path acknowledge the ask once its end is written, not terminate it.

Builds: design 47 G §24, §25; lead answer A-489 (G-22-lead-answers-2.md)

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-19 15:23:13 +01:00

86 lines
3.1 KiB
Go

package steprun
import (
"context"
"encoding/json"
"strings"
"sync"
"testing"
"time"
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
)
// Design 47 G *Asked on a work queue, ended by an event* (§24): the bus counts an ask given back before it ran (a seat list
// not read yet) as a delivery, and that is no run. Only runs that started count toward the poison rule (Puller.Prior, from the
// step key), and a poisoned pipeline step is ended by its step-ended event, so the runner that asked hears it.
func TestOnlyRunsThatStartedCountTowardPoison(t *testing.T) {
stepAsk := func() sdkstep.StepAsk {
return sdkstep.StepAsk{ID: sdkstep.NewID(), Kind: sdkstep.AskStep, Language: sdkstep.AskGo, Asker: "mesh-delivery-pipeline", At: time.Now(),
Step: &sdkstep.StepRun{Pipeline: "main.12.m", Step: sdkstep.StepLint, Module: "m", Artifact: "m:program", Commit: strings.Repeat("a", 40),
Fingerprint: "fp-1", Fetch: sdkstep.Fetch{Repository: "novox/x", Commit: strings.Repeat("a", 40), Dir: "modules/m"}}}
}
for _, c := range []struct {
name string
delivered uint64
prior int
poisoned bool
}{
{"given back four times, never run", sdkstep.AskRuns + 2, 0, false},
{"three runs started and none ended", 3, sdkstep.AskRuns, true},
{"three runs started, delivered many times", sdkstep.AskRuns + 4, sdkstep.AskRuns, true},
} {
t.Run(c.name, func(t *testing.T) {
src, st := NewFakeAsks(), newSteps()
src.Delivered = c.delivered
a := stepAsk()
raw, err := sdkstep.EncodeStepAsk(a)
if err != nil {
t.Fatal(err)
}
src.Publish(sdkstep.AskCheck, raw) // a pipeline step rides the check queue
var mu sync.Mutex
var ended []sdkstep.StepEnded
ran := make(chan struct{}, 1)
p := &Puller{Source: src, Language: sdkstep.AskGo, Node: "shanks", Put: st.put, Capacity: func() int { return 1 },
PullWait: 10 * time.Millisecond, Heartbeat: time.Hour, Prior: func(string) int { return c.prior },
Say: func(event string, body any, id string) error {
if event == "step-ended" {
var e sdkstep.StepEnded
raw, _ := json.Marshal(body)
if err := json.Unmarshal(raw, &e); err == nil {
mu.Lock()
ended = append(ended, e)
mu.Unlock()
}
}
return nil
},
Run: func(ctx context.Context, a sdkstep.StepAsk) (any, error) { ran <- struct{}{}; return nil, nil }}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go p.Pull(ctx)
if c.poisoned {
waitFor(t, "the poisoned ask's end said", func() bool { mu.Lock(); defer mu.Unlock(); return len(ended) == 1 })
mu.Lock()
e := ended[0]
mu.Unlock()
if e.Outcome != sdkstep.OutcomeCouldNotRun || !strings.Contains(e.Said, "poison") || e.Pipeline != "main.12.m" {
t.Fatalf("the end said %+v, want could not run, poison, naming its pipeline", e)
}
select {
case <-ran:
t.Fatal("a poisoned ask ran")
default:
}
return
}
select {
case <-ran:
case <-time.After(5 * time.Second):
t.Fatal("an ask only given back was ended as poison, and never ran")
}
})
}
}