Merge pull request 'Phase 5 (3/4): every test on a bus of its own, at the release the mesh runs (hq ADR 0237)' (#97) from feat/a-suite-that-cannot-flake into main
mesh/delivery delivered
mesh/delivery delivered
This commit was merged in pull request #97.
This commit is contained in:
@@ -69,16 +69,19 @@ func TestAWaiterPinsNoConnectionAndGivesUp(t *testing.T) {
|
||||
done <- err
|
||||
}()
|
||||
}
|
||||
// While they wait, the pool lends nothing to them for longer than a look.
|
||||
pinned := 0
|
||||
for range 10 {
|
||||
time.Sleep(60 * time.Millisecond)
|
||||
if n := int(pool.Stat().AcquiredConns() - base); n > pinned {
|
||||
pinned = n
|
||||
// While they wait, the pool lends nothing to them for longer than a look: **pinned is held throughout**,
|
||||
// so at some moment of the wait fewer than all of them hold one. Asked of the least seen over many
|
||||
// looks, not of the most: a look that lands while every waiter is mid-query is a busy machine, not a
|
||||
// pinned connection, and on a loaded one (the suite's packages at once, the race detector) it did land.
|
||||
least := waiters
|
||||
for range 100 {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
if n := int(pool.Stat().AcquiredConns() - base); n < least {
|
||||
least = n
|
||||
}
|
||||
}
|
||||
if pinned >= waiters {
|
||||
t.Fatalf("%d connections were held by %d waiters", pinned, waiters)
|
||||
if least >= waiters {
|
||||
t.Fatalf("%d waiters held %d connections at every look across their wait", waiters, least)
|
||||
}
|
||||
for range waiters {
|
||||
if err := <-done; !errors.Is(err, ErrNodeBusy) || !strings.Contains(err.Error(), "anchor") {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user