File: options_daemon_timeout_test.go

package info (click to toggle)
golang-github-anacrolix-fuse 0.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,000 kB
  • sloc: makefile: 5; sh: 3
file content (67 lines) | stat: -rw-r--r-- 1,505 bytes parent folder | download
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
65
66
67
// Test for adjustable timeout between a FUSE request and the daemon's response.
//
//go:build darwin
// +build darwin

package fuse_test

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

	"github.com/anacrolix/fuse"
	"github.com/anacrolix/fuse/fs"
	"github.com/anacrolix/fuse/fs/fstestutil"
)

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" {
		return
	}
	if testing.Short() {
		t.Skip("skipping time-based test in short mode")
	}
	maybeParallel(t)
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

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

	// This should fail by the kernel timing out the request.
	req := openRequest{
		Path:      mnt.Dir + "/child",
		Flags:     os.O_WRONLY | os.O_CREATE,
		Perm:      0,
		WantErrno: syscall.ENOTCONN,
	}
	var nothing struct{}
	if err := control.JSON("/").Call(ctx, req, &nothing); err != nil {
		t.Fatalf("calling helper: %v", err)
	}
}