The live tests reached one shared bus and assert, read and remove the mesh's own objects by their fixed names, so packages run in parallel deleted what each other read and the suite passed only one package at a time; a red suite read as noise. internal/testbus starts a server per test, linked in at the nats-server release go.mod pins, and a test holds that pin to the catalogue's bus image and to the facts snapshot's bus when there is one, so the tests never run a bus the mesh does not. The waiter test read a timing (the most connections held at one look) and now reads the state it means (the fewest held across the wait). make check runs the packages in parallel under the race detector, with a timeout.
69 lines
2.1 KiB
Go
69 lines
2.1 KiB
Go
package broker
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/novox/mesh-controller/internal/testbus"
|
|
)
|
|
|
|
// Against a real server, because the questions here are all "does the server accept this" —
|
|
// which a mock would answer by agreeing with whatever this file already believes.
|
|
//
|
|
// Skipped unless MESH_TEST_NATS names one, so the ordinary suite stays fast and offline:
|
|
//
|
|
// go test ./internal/broker/ -run TestAgainstARealServer (each test on a bus of its own: internal/testbus)
|
|
func TestAgainstARealServer(t *testing.T) {
|
|
url := testbus.URL(t)
|
|
js, err := Dial(url)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer js.Close()
|
|
|
|
t.Run("the mesh's own streams are accepted", func(t *testing.T) {
|
|
if err := AssertMeshStreams(js); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
})
|
|
|
|
t.Run("asserting again changes nothing and fails nothing", func(t *testing.T) {
|
|
if err := AssertMeshStreams(js); err != nil {
|
|
t.Fatalf("the second assertion failed, so the controller cannot restart: %v", err)
|
|
}
|
|
})
|
|
|
|
t.Run("a seat's work queue is accepted beside them", func(t *testing.T) {
|
|
seats := []DeclaredSeat{{Name: "telegram-sender", Accepts: []string{"send"}}}
|
|
for _, s := range SeatStreams(seats) {
|
|
if err := js.EnsureStream(s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if c := AllOverlaps(seats); len(c) != 0 {
|
|
t.Fatalf("overlaps the server would refuse: %v", c)
|
|
}
|
|
})
|
|
|
|
t.Run("a module's consumer is accepted and is idempotent", func(t *testing.T) {
|
|
c, ok := ConsumerFor(Principal{Kind: KindModule, Node: "one", Module: "audit",
|
|
Consumes: []string{"shop.order.placed", "billing.invoice.sent"}, PasswordHash: "x"})
|
|
if !ok {
|
|
t.Fatal("no consumer derived")
|
|
}
|
|
if err := js.EnsureConsumer(c); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := js.EnsureConsumer(c); err != nil {
|
|
t.Fatalf("the second assertion failed: %v", err)
|
|
}
|
|
})
|
|
|
|
t.Run("a holder's worker is accepted with its queue group", func(t *testing.T) {
|
|
c, _ := HolderConsumerFor("one", "telegram",
|
|
DeclaredSeat{Name: "telegram-sender", Accepts: []string{"send"}})
|
|
if err := js.EnsureConsumer(c); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
})
|
|
}
|