1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-27 16:07:42 +08:00

fix fuse unmount test

Fuse unmount test uses ipfs instead of ipns, because offline nodes dont actually mount ipns.

Factored out GOOS-aware function to determine unmount command in fuse/mount.

fixed #5475

License: MIT
Signed-off-by: Rob Deutsch <rdeutschob@gmail.com>
This commit is contained in:
rob-deutsch
2018-09-16 14:54:04 +10:00
parent 996281702d
commit 20f5cf7b23
2 changed files with 24 additions and 20 deletions

View File

@ -38,14 +38,9 @@ func ForceUnmount(m Mount) error {
point := m.MountPoint() point := m.MountPoint()
log.Warningf("Force-Unmounting %s...", point) log.Warningf("Force-Unmounting %s...", point)
var cmd *exec.Cmd cmd, err := UnmountCmd(point)
switch runtime.GOOS { if err != nil {
case "darwin": return err
cmd = exec.Command("diskutil", "umount", "force", point)
case "linux":
cmd = exec.Command("fusermount", "-u", point)
default:
return fmt.Errorf("unmount: unimplemented")
} }
errc := make(chan error, 1) errc := make(chan error, 1)
@ -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, // ForceUnmountManyTimes attempts to forcibly unmount a given mount,
// many times. It does so by calling diskutil or fusermount directly. // many times. It does so by calling diskutil or fusermount directly.
// Attempts a given number of times. // Attempts a given number of times.

View File

@ -5,7 +5,6 @@ package node
import ( import (
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec"
"testing" "testing"
"time" "time"
@ -77,24 +76,21 @@ func TestExternalUnmount(t *testing.T) {
} }
// Run shell command to externally unmount the directory // Run shell command to externally unmount the directory
cmd := "fusermount" cmd, err := mount.UnmountCmd(ipfsDir)
args := []string{"-u", ipnsDir} if err != nil {
if err := exec.Command(cmd, args...).Run(); err != nil { t.Fatal(err)
}
if err := cmd.Run(); err != nil {
t.Fatal(err) t.Fatal(err)
} }
// TODO(noffle): it takes a moment for the goroutine that's running fs.Serve to be notified and do its cleanup. // 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) time.Sleep(time.Millisecond * 100)
// Attempt to unmount IPNS; check that it was already unmounted. // Attempt to unmount IPFS; it should unmount successfully.
err = node.Mounts.Ipns.Unmount() err = node.Mounts.Ipfs.Unmount()
if err != mount.ErrNotMounted { if err != mount.ErrNotMounted {
t.Fatal("Unmount should have failed") 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)
}
} }