Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
553bfb0ccf | ||
|
|
3c27ea7a11 | ||
|
|
e2571a6468 | ||
|
|
94bcc14a82 |
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user