summaryrefslogtreecommitdiff
path: root/tests/test_helpers/helpers.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-04-08 20:09:05 +0200
committerJakob Unterwurzacher2018-04-08 20:09:05 +0200
commitcab0cda449c831d1d5bb9b75452428c186079799 (patch)
tree5a7029bb79d7abaa0ab033119f0a7f1e8437cbb0 /tests/test_helpers/helpers.go
parent9d7392a5be7e21aaaf2fb02f19b421c29e304632 (diff)
tests: retry umount
Gnome may still have files open causing spurious test failures.
Diffstat (limited to 'tests/test_helpers/helpers.go')
-rw-r--r--tests/test_helpers/helpers.go28
1 files changed, 22 insertions, 6 deletions
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go
index 971948c..a859129 100644
--- a/tests/test_helpers/helpers.go
+++ b/tests/test_helpers/helpers.go
@@ -221,12 +221,28 @@ func UnmountPanic(dir string) {
}
}
-// UnmountErr tries to unmount "dir" and returns the resulting error.
-func UnmountErr(dir string) error {
- cmd := exec.Command(UnmountScript, "-u", dir)
- cmd.Stdout = os.Stdout
- cmd.Stderr = os.Stderr
- return cmd.Run()
+// UnmountErr tries to unmount "dir", retrying 10 times, and returns the
+// resulting error.
+func UnmountErr(dir string) (err error) {
+ max := 10
+ // When a new filesystem is mounted, Gnome tries to read files like
+ // .xdg-volume-info, autorun.inf, .Trash.
+ // If we try to unmount before Gnome is done, the unmount fails with
+ // "Device or resource busy", causing spurious test failures.
+ // Retry a few times to hide that problem.
+ for i := 1; i <= max; i++ {
+ cmd := exec.Command(UnmountScript, "-u", dir)
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ err = cmd.Run()
+ if err == nil {
+ return nil
+ }
+ code := ExtractCmdExitCode(err)
+ fmt.Printf("UnmountErr: got exit code %d, retrying (%d/%d)\n", code, i, max)
+ time.Sleep(100 * time.Millisecond)
+ }
+ return err
}
// Md5fn returns an md5 string for file "filename"