Files
mesh-host/internal/link/nothing_alive_test.go
T
jschoubben 671f284004
mesh/merge-gate head 671f2840046f merged into trunk 89025ad004d4 — pass: builds mesh-host → ace, g14, novox, shanks; no bus step; every machine composes wi…
mesh/repo-check head 671f2840046f merged into trunk 89025ad004d4 — pass: its merge-check.sh passed
mesh/delivery delivered
Delete the node-engine's alive message, presence replaces it (issue 1158)
2026-10-19 02:15:00 +02:00

54 lines
1.4 KiB
Go

package link
import (
"context"
"sync"
"testing"
"time"
)
// listeningForAlive is a quiet link that also records anything said on an alive subject. The method
// is deliberately kept here: once the bus has no such method, this link can never be asked for it,
// and the test still holds the loop to saying nothing.
type listeningForAlive struct {
*quietLink
mu sync.Mutex
heard int
}
func (l *listeningForAlive) Alive(context.Context, string, []byte) error {
l.mu.Lock()
defer l.mu.Unlock()
l.heard++
return nil
}
func (l *listeningForAlive) count() int {
l.mu.Lock()
defer l.mu.Unlock()
return l.heard
}
// 1158/AC1: the node-engine publishes nothing on its alive subject (novox/hq ADR 0429 §7, ADR 0433
// §3: presence replaces the alive message). The loop runs over a fake bus and no alive is published,
// neither at the start nor on a tick.
func TestTheLinkLoopPublishesNoAlive(t *testing.T) {
m, _ := aMember(t)
l := &listeningForAlive{quietLink: newQuietLink()}
q := aQueue(m, nil, &keptInMemory{})
ctx, stop := context.WithCancel(context.Background())
done := make(chan error, 1)
go func() { done <- serve(ctx, l, m, q, nil, time.Second) }()
time.Sleep(300 * time.Millisecond)
stop()
select {
case <-done:
case <-time.After(5 * time.Second):
t.Fatal("the loop did not end")
}
if n := l.count(); n != 0 {
t.Fatalf("the node published %d alive messages (1158/AC1)", n)
}
}