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.
50 lines
1.5 KiB
Go
50 lines
1.5 KiB
Go
package inventory
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// **The store the tests run is the store the mesh runs** (novox/hq ADR 0227 rule 9, ADR 0237). In a merge
|
|
// check the build seat raises the store of the major release the facts snapshot says the mesh's store
|
|
// runs; this holds the two equal there, so a test passing here is a test passing on that release. Without
|
|
// a snapshot — on a workstation — it says what it ran against and compares nothing.
|
|
func TestTheStoreTheTestsRunIsTheStoreTheMeshRuns(t *testing.T) {
|
|
inv := ForTest(t)
|
|
ran, err := inv.ServerVersionForTest(t)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
path := os.Getenv("MESH_FACTS")
|
|
if path == "" {
|
|
t.Logf("the tests ran the store at %s; with no MESH_FACTS, nothing to compare it with", ran)
|
|
return
|
|
}
|
|
body, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var f struct {
|
|
Versions struct {
|
|
Store string `json:"store"`
|
|
} `json:"versions"`
|
|
}
|
|
if err := json.Unmarshal(body, &f); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
major := func(v string) string { m, _, _ := strings.Cut(strings.TrimSpace(v), "."); return m }
|
|
if f.Versions.Store != "" && major(ran) != major(f.Versions.Store) {
|
|
t.Errorf("the tests ran the store at %s and the mesh's store runs %s", ran, f.Versions.Store)
|
|
}
|
|
}
|
|
|
|
// ServerVersionForTest is the store's own word for its release.
|
|
func (i *Inventory) ServerVersionForTest(t *testing.T) (string, error) {
|
|
t.Helper()
|
|
var v string
|
|
err := i.store.Pool().QueryRow(t.Context(), `show server_version`).Scan(&v)
|
|
return v, err
|
|
}
|