github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/backend/cache/cache_mount_unix_test.go (about) 1 // +build !plan9,!windows 2 3 package cache_test 4 5 import ( 6 "os" 7 "testing" 8 "time" 9 10 "bazil.org/fuse" 11 fusefs "bazil.org/fuse/fs" 12 "github.com/ncw/rclone/cmd/mount" 13 "github.com/ncw/rclone/cmd/mountlib" 14 "github.com/ncw/rclone/fs" 15 "github.com/stretchr/testify/require" 16 ) 17 18 func (r *run) mountFs(t *testing.T, f fs.Fs) { 19 device := f.Name() + ":" + f.Root() 20 var options = []fuse.MountOption{ 21 fuse.MaxReadahead(uint32(mountlib.MaxReadAhead)), 22 fuse.Subtype("rclone"), 23 fuse.FSName(device), fuse.VolumeName(device), 24 fuse.NoAppleDouble(), 25 fuse.NoAppleXattr(), 26 //fuse.AllowOther(), 27 } 28 err := os.MkdirAll(r.mntDir, os.ModePerm) 29 require.NoError(t, err) 30 c, err := fuse.Mount(r.mntDir, options...) 31 require.NoError(t, err) 32 filesys := mount.NewFS(f) 33 server := fusefs.New(c, nil) 34 35 // Serve the mount point in the background returning error to errChan 36 r.unmountRes = make(chan error, 1) 37 go func() { 38 err := server.Serve(filesys) 39 closeErr := c.Close() 40 if err == nil { 41 err = closeErr 42 } 43 r.unmountRes <- err 44 }() 45 46 // check if the mount process has an error to report 47 <-c.Ready 48 require.NoError(t, c.MountError) 49 50 r.unmountFn = func() error { 51 // Shutdown the VFS 52 filesys.VFS.Shutdown() 53 return fuse.Unmount(r.mntDir) 54 } 55 56 r.vfs = filesys.VFS 57 r.isMounted = true 58 } 59 60 func (r *run) unmountFs(t *testing.T, f fs.Fs) { 61 var err error 62 63 for i := 0; i < 4; i++ { 64 err = r.unmountFn() 65 if err != nil { 66 //log.Printf("signal to umount failed - retrying: %v", err) 67 time.Sleep(3 * time.Second) 68 continue 69 } 70 break 71 } 72 require.NoError(t, err) 73 err = <-r.unmountRes 74 require.NoError(t, err) 75 err = r.vfs.CleanUp() 76 require.NoError(t, err) 77 r.isMounted = false 78 }