Compare commits

..
Author SHA1 Message Date
mesh-tools 553bfb0ccf Merge pull request 'The forge's whole-seat test ends NOT RUN when its npm tooling is missing (H-A-294)' (#730) from fix/47-H1-gitea-whole-test-not-run into main 2026-11-21 18:30:10 +00:00
mesh-tools 3c27ea7a11 Merge pull request 'The zfs keeper test's race, and a non-root peer whose write is cut is told only root (A-37)' (#729) from fix/47-H1-zfs-keeper-test into main 2026-11-21 18:29:59 +00:00
jschoubben e2571a6468 gitea: the seat git's whole test says NOT RUN where node, npm or its npm packages are missing
The Go integration level fetches the forge module's tree without node_modules and
without network, so TestTheSeatGitWholeOverARealBus failed every pipeline carrying
the forge. It now checks its needs first and skips by name, as the Node build
module's realMachine does; with its needs present it runs whole as before.

Issue 1960 (H1).
Builds: design 47 H H-A-294
2026-11-21 19:26:31 +01:00
jschoubben 94bcc14a82 zfs: the keeper's socket test no longer races, and a refused peer is told so
The test switched the peer's uid in a plain variable the keeper's serving
goroutines read, a data race that fails it under -race; it is an atomic now.
A peer the keeper refuses could also get "broken pipe" instead of the
refusal, when the keeper closed before the request was written: the client
now reads the refusal that waits on the socket. A request larger than the
socket's buffer makes that case happen every time.

Builds: A-37 (only root opens the keeper's socket; a non-root peer is told so); design 47 H section 10 rows 165 and 167 (hq branch design/47-H1-answers-59, 81fa1ee4)
2026-11-21 19:26:14 +01:00
3 changed files with 38 additions and 7 deletions
@@ -344,14 +344,27 @@ func numbers(v any) []float64 {
return out
}
// needTheModulesPackages ends the test NOT RUN, never failed, where what it builds and runs with is missing: node and npm
// on the PATH and the module's installed SDK package under node_modules. The Go integration level is given the tree
// without its npm packages and no network (issue 1960, H-A-294), as the Node build module's realMachine skips by name.
func needTheModulesPackages(t *testing.T, dir string) {
t.Helper()
for _, p := range []string{"node", "npm"} {
if _, err := exec.LookPath(p); err != nil {
t.Skipf("NOT RUN: no %s installed where this check runs; proven in a working copy of the module after npm install", p)
}
}
if _, err := os.Stat(filepath.Join(dir, "node_modules", "@novox", "mesh-sdk")); err != nil {
t.Skipf("NOT RUN: the forge module's npm packages are not installed in %s (%v); proven in a working copy of the module after npm install", dir, err)
}
}
func TestTheSeatGitWholeOverARealBus(t *testing.T) {
dir, err := filepath.Abs(filepath.Join("..", ".."))
if err != nil {
t.Fatal(err)
}
if _, err := os.Stat(filepath.Join(dir, "node_modules", "@novox", "mesh-sdk")); err != nil {
t.Fatalf("the forge module's packages are not installed in %s (npm install first): %v", dir, err)
}
needTheModulesPackages(t, dir)
build := exec.Command("npm", "run", "build")
build.Dir = dir
if out, err := build.CombinedOutput(); err != nil {
+5
View File
@@ -328,6 +328,11 @@ func (c keeperClient) exchange(r KeeperRequest) (a KeeperAnswer, err error, unan
defer conn.Close()
_ = conn.SetDeadline(time.Now().Add(KeeperTimeout))
if err := json.NewEncoder(conn).Encode(r); err != nil {
// A keeper that refuses the peer answers and closes without reading, so the write can meet a closed socket
// (broken pipe) while the refusal already waits to be read: the refusal is the answer (issue 1960).
if derr := json.NewDecoder(conn).Decode(&a); derr == nil && a.Error != "" {
return a, errors.New(a.Error), false
}
return KeeperAnswer{}, err, true
}
if err := json.NewDecoder(conn).Decode(&a); err != nil {
+17 -4
View File
@@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"strings"
"sync/atomic"
"testing"
)
@@ -91,10 +92,12 @@ func shortTempDir(prefix string) (string, error) {
// keeper answering it acts as with the bus down, with a warning (A-8).
func TestOnlyRootOpensTheKeepersSocketAndANeedlessKeeperIsTheBusDown(t *testing.T) {
st := memStates{}
uid := 0
// The peer's uid is read by the keeper's serving goroutines and switched by the test: an atomic, so no connection
// sees it half-written (issue 1960: a data race failed the test under -race).
var uid atomic.Int32
k := &Keeper{Emit: func(string, any) error { return nil }, States: st,
Call: func(string, any) (json.RawMessage, error) { return nil, errors.New("down") },
PeerOf: func(net.Conn) (int, error) { return uid, nil }}
PeerOf: func(net.Conn) (int, error) { return int(uid.Load()), nil }}
dir, err := shortTempDir("zk")
if err != nil {
t.Fatal(err)
@@ -121,13 +124,21 @@ func TestOnlyRootOpensTheKeepersSocketAndANeedlessKeeperIsTheBusDown(t *testing.
if _, err := c.call(ToolSchedule, map[string]any{}); err == nil || !strings.Contains(err.Error(), "down") {
t.Errorf("an invoke that failed: %v", err)
}
uid = 1000
uid.Store(1000)
if err := c.Put(StateSchedule, "x", 1); err == nil || !strings.Contains(err.Error(), "only root") {
t.Errorf("a peer that is not root: %v", err)
}
// A request larger than the socket's buffer: the keeper refuses and closes before it is written whole, so the write
// meets a closed socket every time; the peer is still told it is not root (issue 1960).
if err := c.Put(StateSchedule, "y", strings.Repeat("x", 1<<20)); err == nil || !strings.Contains(err.Error(), "only root") {
t.Errorf("a peer that is not root, its write cut: %v", err)
}
if _, left := st["schedule/x"]; left {
t.Errorf("a refused peer's call was read")
}
if _, left := st["schedule/y"]; left {
t.Errorf("a refused peer's cut call was read")
}
// No socket variable: the machine keeps no bus and says so.
t.Setenv(KeeperSocketEnv, "")
m := newFake(t).machine()
@@ -151,6 +162,8 @@ func TestOnlyRootOpensTheKeepersSocketAndANeedlessKeeperIsTheBusDown(t *testing.
if err != nil {
t.Fatal(err)
}
// The socket is bound before the call below, so the call waits in its backlog until Serve accepts it: the keeper
// is up from the moment Listen returns, whenever its goroutine runs.
lctx, lcancel := context.WithCancel(context.Background())
defer lcancel()
go (&Keeper{Emit: func(string, any) error { return nil }, States: memStates{}, PeerOf: func(net.Conn) (int, error) { return 0, nil },
@@ -159,7 +172,7 @@ func TestOnlyRootOpensTheKeepersSocketAndANeedlessKeeperIsTheBusDown(t *testing.
t.Errorf("a keeper that came up later is not used: %v", err)
}
t.Setenv(KeeperSocketEnv, sock)
uid = 0
uid.Store(0)
m2 := newFake(t).machine()
m2.JoinBus()
if m2.Emit == nil || m2.States == nil || m2.Call == nil || m2.keeper == nil {