Skip to content

Commit

Permalink
Merge pull request #5476 from rob-deutsch/fix/5475
Browse files Browse the repository at this point in the history
fix fuse unmount test
  • Loading branch information
Stebalien authored Sep 19, 2018
2 parents 370bd22 + 20f5cf7 commit 61f31e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
24 changes: 16 additions & 8 deletions fuse/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,9 @@ func ForceUnmount(m Mount) error {
point := m.MountPoint()
log.Warningf("Force-Unmounting %s...", point)

var cmd *exec.Cmd
switch runtime.GOOS {
case "darwin":
cmd = exec.Command("diskutil", "umount", "force", point)
case "linux":
cmd = exec.Command("fusermount", "-u", point)
default:
return fmt.Errorf("unmount: unimplemented")
cmd, err := UnmountCmd(point)
if err != nil {
return err
}

errc := make(chan error, 1)
Expand All @@ -69,6 +64,19 @@ func ForceUnmount(m Mount) error {
}
}

// UnmountCmd creates an exec.Cmd that is GOOS-specific
// for unmount a FUSE mount
func UnmountCmd(point string) (*exec.Cmd, error) {
switch runtime.GOOS {
case "darwin":
return exec.Command("diskutil", "umount", "force", point), nil
case "linux":
return exec.Command("fusermount", "-u", point), nil
default:
return nil, fmt.Errorf("unmount: unimplemented")
}
}

// ForceUnmountManyTimes attempts to forcibly unmount a given mount,
// many times. It does so by calling diskutil or fusermount directly.
// Attempts a given number of times.
Expand Down
20 changes: 8 additions & 12 deletions fuse/node/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package node
import (
"io/ioutil"
"os"
"os/exec"
"testing"
"time"

Expand Down Expand Up @@ -77,24 +76,21 @@ func TestExternalUnmount(t *testing.T) {
}

// Run shell command to externally unmount the directory
cmd := "fusermount"
args := []string{"-u", ipnsDir}
if err := exec.Command(cmd, args...).Run(); err != nil {
cmd, err := mount.UnmountCmd(ipfsDir)
if err != nil {
t.Fatal(err)
}

if err := cmd.Run(); err != nil {
t.Fatal(err)
}

// TODO(noffle): it takes a moment for the goroutine that's running fs.Serve to be notified and do its cleanup.
time.Sleep(time.Millisecond * 100)

// Attempt to unmount IPNS; check that it was already unmounted.
err = node.Mounts.Ipns.Unmount()
if err != mount.ErrNotMounted {
t.Fatal("Unmount should have failed")
}

// Attempt to unmount IPFS; it should unmount successfully.
err = node.Mounts.Ipfs.Unmount()
if err != nil {
t.Fatal(err)
if err != mount.ErrNotMounted {
t.Fatal("Unmount should have failed")
}
}

0 comments on commit 61f31e5

Please sign in to comment.