summaryrefslogtreecommitdiff
path: root/tests/test_helpers
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-04-07 15:21:05 +0200
committerJakob Unterwurzacher2018-04-07 15:24:00 +0200
commit22031d7e531985e9e94d694e74fb00da99de72a5 (patch)
treea3342b55aecc3076f40a08fd968fdbac3f82f8ad /tests/test_helpers
parent4e5783591f9874e2c7336598c96ebd2c5840bd5b (diff)
tests: matrix: check for fd leaks
And fix two in test_helpers.Mount(). Leftover fds can cause an unmount failure like this later: fusermount: failed to unmount /tmp/gocryptfs-test-parent/873632270/default-plain: Device or resource busy so try to catch them early.
Diffstat (limited to 'tests/test_helpers')
-rw-r--r--tests/test_helpers/helpers.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go
index f92fb79..971948c 100644
--- a/tests/test_helpers/helpers.go
+++ b/tests/test_helpers/helpers.go
@@ -178,9 +178,14 @@ func Mount(c string, p string, showOutput bool, extraArgs ...string) error {
if err != nil {
return err
}
+ // We can close the fd after cmd.Run() has executed
+ defer pw.Close()
cmd.Stderr = pw
cmd.Stdout = pw
- go func() { io.Copy(os.Stdout, pr) }()
+ go func() {
+ io.Copy(os.Stdout, pr)
+ pr.Close()
+ }()
}
return cmd.Run()
@@ -412,3 +417,23 @@ func ExtractCmdExitCode(err error) int {
code := err2.Sys().(syscall.WaitStatus).ExitStatus()
return code
}
+
+// ListFds lists our open file descriptors.
+// We use /dev/fd because it exists on both Linux and MacOS.
+func ListFds() []string {
+ f, err := os.Open("/dev/fd")
+ if err != nil {
+ log.Panic(err)
+ }
+ defer f.Close()
+ names, err := f.Readdirnames(0)
+ if err != nil {
+ log.Panic(err)
+ }
+ for i, n := range names {
+ // Note: Readdirnames filters "." and ".."
+ target, _ := os.Readlink("/dev/fd/" + n)
+ names[i] = n + "=" + target
+ }
+ return names
+}