File: options_daemon_timeout_test.go

package info (click to toggle)
golang-bazil-fuse 0.0~git20160811.0.371fbbd-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, buster-backports, experimental, sid
  • size: 728 kB
  • sloc: sh: 26; makefile: 5
file content (64 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Test for adjustable timeout between a FUSE request and the daemon's response.
//
// +build darwin freebsd

package fuse_test

import (
	"os"
	"runtime"
	"syscall"
	"testing"
	"time"

	"bazil.org/fuse"
	"bazil.org/fuse/fs"
	"bazil.org/fuse/fs/fstestutil"
	"golang.org/x/net/context"
)

type slowCreaterDir struct {
	fstestutil.Dir
}

var _ fs.NodeCreater = slowCreaterDir{}

func (c slowCreaterDir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (fs.Node, fs.Handle, error) {
	time.Sleep(10 * time.Second)
	// pick a really distinct error, to identify it later
	return nil, nil, fuse.Errno(syscall.ENAMETOOLONG)
}

func TestMountOptionDaemonTimeout(t *testing.T) {
	if runtime.GOOS != "darwin" && runtime.GOOS != "freebsd" {
		return
	}
	if testing.Short() {
		t.Skip("skipping time-based test in short mode")
	}
	t.Parallel()

	mnt, err := fstestutil.MountedT(t,
		fstestutil.SimpleFS{slowCreaterDir{}},
		nil,
		fuse.DaemonTimeout("2"),
	)
	if err != nil {
		t.Fatal(err)
	}
	defer mnt.Close()

	// This should fail by the kernel timing out the request.
	f, err := os.Create(mnt.Dir + "/child")
	if err == nil {
		f.Close()
		t.Fatal("expected an error")
	}
	perr, ok := err.(*os.PathError)
	if !ok {
		t.Fatalf("expected PathError, got %T: %v", err, err)
	}
	if perr.Err == syscall.ENAMETOOLONG {
		t.Fatalf("expected other than ENAMETOOLONG, got %T: %v", err, err)
	}
}