Refactored SampleTest.Destroy.

geesefs-0-30-9
Aaron Jacobs 2015-03-20 10:47:46 +11:00
parent 03f5453297
commit 08f495e8b0
1 changed files with 16 additions and 4 deletions

View File

@ -82,6 +82,14 @@ func (t *SampleTest) initialize(
// Unmount the file system and clean up. Panics on error. // Unmount the file system and clean up. Panics on error.
func (t *SampleTest) Destroy() { func (t *SampleTest) Destroy() {
err := t.destroy()
if err != nil {
panic(err)
}
}
// Like Destroy, but doesn't panic.
func (t *SampleTest) destroy() (err error) {
// Was the file system mounted? // Was the file system mounted?
if t.mfs == nil { if t.mfs == nil {
return return
@ -90,7 +98,7 @@ func (t *SampleTest) Destroy() {
// Unmount the file system. Try again on "resource busy" errors. // Unmount the file system. Try again on "resource busy" errors.
delay := 10 * time.Millisecond delay := 10 * time.Millisecond
for { for {
err := t.mfs.Unmount() err = t.mfs.Unmount()
if err == nil { if err == nil {
break break
} }
@ -102,10 +110,14 @@ func (t *SampleTest) Destroy() {
continue continue
} }
panic("MountedFileSystem.Unmount: " + err.Error()) err = fmt.Errorf("MountedFileSystem.Unmount: %v", err)
return
} }
if err := t.mfs.Join(t.Ctx); err != nil { if err = t.mfs.Join(t.Ctx); err != nil {
panic("MountedFileSystem.Join: " + err.Error()) err = fmt.Errorf("MountedFileSystem.Join: %v", err)
return
} }
return
} }