From cab0cda449c831d1d5bb9b75452428c186079799 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 8 Apr 2018 20:09:05 +0200 Subject: tests: retry umount Gnome may still have files open causing spurious test failures. --- tests/test_helpers/helpers.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'tests') 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" -- cgit v1.2.3