Files
mesh-delivery/modules/mesh-delivery-pipeline/internal/pipeline/consumers_test.go
T
jschoubben 4b47e88369 RN25: runner_health reads the consumer facts mesh-sdk's ledger writes
The runner's own writer of its consumer's oldest unacknowledged delivery is
replaced by mesh-sdk's consumer ledger: each message the hub hands a handler is
noted delivered, and applied when the handler acknowledges or ends it; one it
asks again stays unacknowledged. The key form is the same, a key per consumer
by its name in the state consumers. A runner that heard no event yet is healthy.

Builds: design 47 G §76, §468, §495; lead answers A-166, A-176

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 05:42:33 +01:00

61 lines
1.9 KiB
Go

package pipeline
import (
"encoding/json"
"errors"
"strings"
"testing"
"time"
"git.novox.be/novox/mesh-sdk/go/process"
)
type mapKept map[string]json.RawMessage
func (m mapKept) Keys() ([]string, error) {
var out []string
for k := range m {
out = append(out, k)
}
return out, nil
}
func (m mapKept) Value(k string) (json.RawMessage, error) { return m[k], nil }
type failingKept struct{}
func (failingKept) Keys() ([]string, error) { return nil, errors.New("no bucket") }
func (failingKept) Value(string) (json.RawMessage, error) { return nil, errors.New("no bucket") }
// TestHealth: runner_health is healthy when the runner answers show and each consumer is less than five minutes behind,
// and otherwise names each consumer behind (§76, §468, §495; RN25, A-164).
func TestHealth(t *testing.T) {
now := time.Date(2026, 11, 12, 10, 0, 0, 0, time.UTC)
age := func(name string, since time.Duration) mapKept {
a := process.ConsumerFacts{Name: name}
if since > 0 {
a.OldestUnacknowledged = now.Add(-since)
}
raw, _ := json.Marshal(a)
return mapKept{name: raw}
}
rows := []struct {
name string
pipelines Kept
consumers Kept
healthy bool
says string
}{
{"none waiting", mapKept{}, age("n_runner", 0), true, "less than 5m0s behind"},
{"four minutes", mapKept{}, age("n_runner", 4*time.Minute), true, ""},
{"six minutes names the consumer", mapKept{}, age("n_runner", 6*time.Minute), false, "n_runner (its oldest unacknowledged message waits 6m0s)"},
{"show does not answer", failingKept{}, age("n_runner", 0), false, "does not answer show"},
{"no event heard yet", mapKept{}, mapKept{}, true, "has heard no event yet"},
}
for _, r := range rows {
a := Health(r.pipelines, r.consumers, now)
if a.Healthy != r.healthy || !strings.Contains(a.Why, r.says) {
t.Errorf("%s: healthy %v %q; want %v saying %q", r.name, a.Healthy, a.Why, r.healthy, r.says)
}
}
}