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) } }