tests: add fd leak retry logic to UnmountErr, really return error
Give the gocryptfs process one extra millisecond to close files. Allows us to drop several other sleeps. UnmountErr now really returns an error when it detects an fd leak instead of just printing a message.
This commit is contained in:
parent
5aa1755cbc
commit
772afa93f9
@ -4,7 +4,6 @@ import (
|
||||
"os"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
||||
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
||||
@ -38,9 +37,6 @@ func TestCtlSock(t *testing.T) {
|
||||
t.Errorf("We should get a warning about non-canonical paths here")
|
||||
}
|
||||
}
|
||||
// Give the running gocryptfs process a little bit of time to close lingering
|
||||
// sockets. Avoid triggering the FD leak detector.
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
}
|
||||
|
||||
func TestCtlSockDecrypt(t *testing.T) {
|
||||
@ -91,9 +87,6 @@ func TestCtlSockDecrypt(t *testing.T) {
|
||||
t.Errorf("want=%q got=%q", p, response.Result)
|
||||
}
|
||||
}
|
||||
// Give the running gocryptfs process a little bit of time to close lingering
|
||||
// sockets. Avoid triggering the FD leak detector.
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
}
|
||||
|
||||
func TestCtlSockDecryptCrash(t *testing.T) {
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"io/ioutil"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
||||
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
||||
@ -68,9 +67,6 @@ func TestCtlSockPathOps(t *testing.T) {
|
||||
if response.ErrNo != int32(syscall.ENOENT) {
|
||||
t.Errorf("File should not exist: ErrNo=%d ErrText=%s", response.ErrNo, response.ErrText)
|
||||
}
|
||||
// Give the running gocryptfs process a little bit of time to close lingering
|
||||
// sockets. Avoid triggering the FD leak detector.
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
}
|
||||
|
||||
// We should not panic when somebody feeds requests that make no sense
|
||||
@ -89,7 +85,4 @@ func TestCtlSockCrash(t *testing.T) {
|
||||
// Try to crash it
|
||||
req := ctlsock.RequestStruct{DecryptPath: "gocryptfs.longname.XXX_TestCtlSockCrash_XXX.name"}
|
||||
test_helpers.QueryCtlSock(t, sock, req)
|
||||
// Give the running gocryptfs process a little bit of time to close lingering
|
||||
// sockets. Avoid triggering the FD leak detector.
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package reverse_test
|
||||
import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
||||
"github.com/rfjakob/gocryptfs/tests/test_helpers"
|
||||
@ -102,9 +101,6 @@ func testExclude(t *testing.T, flag string) {
|
||||
t.Errorf("File %q / %q is hidden, but should be visible", pOk[i], v)
|
||||
}
|
||||
}
|
||||
// Give the running gocryptfs process a little bit of time to close lingering
|
||||
// sockets. Avoid triggering the FD leak detector.
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
}
|
||||
|
||||
func TestExclude(t *testing.T) {
|
||||
|
@ -141,14 +141,22 @@ func UnmountErr(dir string) (err error) {
|
||||
for i := 1; i <= max; i++ {
|
||||
if pid > 0 {
|
||||
fdsNow = ListFds(pid)
|
||||
if len(fdsNow) > len(fds) {
|
||||
// File close on FUSE is asynchronous, closing a socket
|
||||
// when testing -ctlsock as well. Wait one extra millisecond
|
||||
// and hope that all close commands get through to the gocryptfs
|
||||
// process.
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
fdsNow = ListFds(pid)
|
||||
}
|
||||
}
|
||||
cmd := exec.Command(UnmountScript, "-u", dir)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
if err == nil {
|
||||
if pid > 0 && len(fdsNow) > len(fds) {
|
||||
fmt.Printf("FD leak? Details:\nold=%v \nnew=%v\n", fds, fdsNow)
|
||||
if len(fdsNow) > len(fds) {
|
||||
return fmt.Errorf("FD leak? pid=%d dir=%q, fds:\nold=%v \nnew=%v\n", pid, dir, fds, fdsNow)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user