zfs: the keeper tests' socket directory is the shortest that works
In the test's temporary directory, or /tmp when the socket path would pass 100 characters, so a long TMPDIR cannot fail the bind. Builds: design 42 zfs-owns-zfs §18, A-37
This commit is contained in:
@@ -65,6 +65,17 @@ func TestTheKeeperAnswersOnlyItsClosedListOfCalls(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// shortTempDir is a directory in the test's temporary directory, or in /tmp when a socket in it (`k/k.sock`) would pass 100
|
||||||
|
// characters, the most a unix socket path takes, so a long TMPDIR cannot fail the bind.
|
||||||
|
func shortTempDir(prefix string) (string, error) {
|
||||||
|
dir, err := os.MkdirTemp("", prefix)
|
||||||
|
if err != nil || len(filepath.Join(dir, "k", "k.sock")) <= 100 {
|
||||||
|
return dir, err
|
||||||
|
}
|
||||||
|
os.RemoveAll(dir)
|
||||||
|
return os.MkdirTemp("/tmp", prefix)
|
||||||
|
}
|
||||||
|
|
||||||
// A-37: only root opens the socket; a root process says and reads through it as through a bus of its own, and with no
|
// A-37: only root opens the socket; a root process says and reads through it as through a bus of its own, and with no
|
||||||
// keeper answering it acts as with the bus down, with a warning (A-8).
|
// keeper answering it acts as with the bus down, with a warning (A-8).
|
||||||
func TestOnlyRootOpensTheKeepersSocketAndANeedlessKeeperIsTheBusDown(t *testing.T) {
|
func TestOnlyRootOpensTheKeepersSocketAndANeedlessKeeperIsTheBusDown(t *testing.T) {
|
||||||
@@ -73,7 +84,7 @@ func TestOnlyRootOpensTheKeepersSocketAndANeedlessKeeperIsTheBusDown(t *testing.
|
|||||||
k := &Keeper{Emit: func(string, any) error { return nil }, States: st,
|
k := &Keeper{Emit: func(string, any) error { return nil }, States: st,
|
||||||
Call: func(string, any) (json.RawMessage, error) { return nil, errors.New("down") },
|
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 uid, nil }}
|
||||||
dir, err := os.MkdirTemp("", "zk")
|
dir, err := shortTempDir("zk")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -148,7 +159,7 @@ func TestOnlyRootOpensTheKeepersSocketAndANeedlessKeeperIsTheBusDown(t *testing.
|
|||||||
// A-37: a root process whose keeper does not answer acts as with the bus down and says so, once, in a warning, for the
|
// A-37: a root process whose keeper does not answer acts as with the bus down and says so, once, in a warning, for the
|
||||||
// hand acts, the forgetting of applied keys and the pause alike.
|
// hand acts, the forgetting of applied keys and the pause alike.
|
||||||
func TestAKeeperThatDoesNotAnswerIsWarnedOnce(t *testing.T) {
|
func TestAKeeperThatDoesNotAnswerIsWarnedOnce(t *testing.T) {
|
||||||
dir, err := os.MkdirTemp("", "keeper-down")
|
dir, err := shortTempDir("kd")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user