35 lines
1.5 KiB
Go
35 lines
1.5 KiB
Go
package link
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// What the bus module says of its users' connections, read back as advisories (novox/hq ADR 0357, issue
|
|
// 270): one per user and kind, each closure counted once however often it is said.
|
|
//
|
|
// go test ./internal/link/ -run TestNatsBusFaults (each test on a bus of its own: internal/testbus)
|
|
|
|
func sayClosure(t *testing.T, s *Server, event string, c BusClosure) {
|
|
t.Helper()
|
|
body, _ := json.Marshal(c)
|
|
if _, err := s.js.Context().Publish(EventSubject(BusModule, event), body); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestTheControllersOwnSlowConsumerAndItsClosedConnectionAreOneAdvisory(t *testing.T) {
|
|
at := time.Date(2026, 10, 14, 12, 0, 0, 0, time.UTC)
|
|
own := []Advisory{{Kind: AdvisorySlowConsumer, ID: "controller", Said: "the controller fell behind", First: at, Last: at, Count: 1}}
|
|
closed := BusClosures([]BusClosure{{User: "controller", CID: 5, Reason: "Slow Consumer (Pending Bytes)",
|
|
Opened: at.Add(-time.Hour), Closed: at.Add(time.Minute)}}, []string{AdvisorySlowConsumer}, at.Add(-time.Hour))
|
|
got := MergeAdvisories(own, closed)
|
|
if len(got) != 1 || got[0].Count != 1 || !got[0].Last.Equal(at.Add(time.Minute)) || got[0].User != "controller" {
|
|
t.Fatalf("merged as %+v: one fall behind, told to the client and closed by the server, is counted once", got)
|
|
}
|
|
}
|
|
|
|
// **A busy hour is read up to a bound, and says it was cut** (review of #326): a storm of closures must not
|
|
// spend a watchdog tick, and a count cut short is a floor, said as one.
|