aboutsummaryrefslogtreecommitdiff
path: root/tests/test_helpers
diff options
context:
space:
mode:
authorJakob Unterwurzacher2019-10-06 19:04:16 +0200
committerJakob Unterwurzacher2019-10-06 19:37:51 +0200
commit1fb18f4a9ef2bbbc6e7c774fa064808a3952bb3f (patch)
tree5e27aa2b53c1af53e280dea269cf0039f499f888 /tests/test_helpers
parentd361f6e35bb97ef8f060131ea5b29f922e613c49 (diff)
tests: filter leaked fds by prefix
When running $ go test ./tests/matrix/ in isolation, it failed like this: fd leak? before, after: [0r=/dev/null 3w=/dev/null 5r=/proc/8078/fd (hidden:4)] [0r=/dev/null 3w=/dev/null 5w=/tmp/go-build366655199/b001/testlog.txt 7r=/proc/8078/fd (hidden:4)] Filter by prefix to get rid of this spurious test failure.
Diffstat (limited to 'tests/test_helpers')
-rw-r--r--tests/test_helpers/mount_unmount.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/tests/test_helpers/mount_unmount.go b/tests/test_helpers/mount_unmount.go
index 453ea20..7b5dafa 100644
--- a/tests/test_helpers/mount_unmount.go
+++ b/tests/test_helpers/mount_unmount.go
@@ -91,7 +91,7 @@ func Mount(c string, p string, showOutput bool, extraArgs ...string) error {
}
// Save PID and open FDs
- MountInfo[p] = mountInfo{pid, ListFds(pid)}
+ MountInfo[p] = mountInfo{pid, ListFds(pid, "")}
return nil
}
@@ -160,13 +160,13 @@ func UnmountErr(dir string) (err error) {
// when testing "-ctlsock" is as well. Wait a little and
// hope that all close commands get through to the gocryptfs
// process.
- fdsNow = ListFds(pid)
+ fdsNow = ListFds(pid, "")
if len(fdsNow) <= len(fds)+maxCacheFds {
break
}
fmt.Printf("UnmountErr: fdsOld=%d fdsNow=%d, retrying\n", len(fds), len(fdsNow))
time.Sleep(10 * time.Millisecond)
- fdsNow = ListFds(pid)
+ fdsNow = ListFds(pid, "")
}
}
cmd := exec.Command(UnmountScript, "-u", dir)
@@ -187,8 +187,8 @@ func UnmountErr(dir string) (err error) {
}
// ListFds lists the open file descriptors for process "pid". Pass pid=0 for
-// ourselves.
-func ListFds(pid int) []string {
+// ourselves. Pass a prefix to ignore all paths that do not start with "prefix".
+func ListFds(pid int, prefix string) []string {
// We need /proc to get the list of fds for other processes. Only exists
// on Linux.
if runtime.GOOS != "linux" && pid > 0 {
@@ -211,7 +211,7 @@ func ListFds(pid int) []string {
log.Panic(err)
}
var out []string
- hidden := 0
+ var filtered []string
for _, n := range names {
fdPath := dir + "/" + n
fi, err := os.Lstat(fdPath)
@@ -235,11 +235,15 @@ func ListFds(pid int) []string {
// creates spurious test failures. Ignore all pipes.
// Also get rid of the "eventpoll" fd that is always there and not
// interesting.
- hidden++
+ filtered = append(filtered, target)
+ continue
+ }
+ if prefix != "" && !strings.HasPrefix(target, prefix) {
+ filtered = append(filtered, target)
continue
}
out = append(out, n+"="+target)
}
- out = append(out, fmt.Sprintf("(hidden:%d)", hidden))
+ out = append(out, fmt.Sprintf("(filtered: %s)", strings.Join(filtered, ", ")))
return out
}