Commit d7ac6b93 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fuse/test: use channel in NotifyTest to obviate ThreadSanitizerSync.

parent 66ff11b1
...@@ -2,7 +2,6 @@ package test ...@@ -2,7 +2,6 @@ package test
import ( import (
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"testing" "testing"
"time" "time"
...@@ -12,20 +11,47 @@ import ( ...@@ -12,20 +11,47 @@ import (
"github.com/hanwen/go-fuse/fuse/pathfs" "github.com/hanwen/go-fuse/fuse/pathfs"
) )
var _ = log.Println
type NotifyFs struct { type NotifyFs struct {
pathfs.FileSystem pathfs.FileSystem
size uint64 size uint64
exist bool exist bool
sizeChan chan uint64
existChan chan bool
}
func newNotifyFs() *NotifyFs {
return &NotifyFs{
FileSystem: pathfs.NewDefaultFileSystem(),
sizeChan: make(chan uint64, 1),
existChan: make(chan bool, 1),
}
}
func (fs *NotifyFs) Exists() bool {
select {
case s := <-fs.existChan:
fs.exist = s
default:
}
return fs.exist
}
func (fs *NotifyFs) Size() uint64 {
select {
case s := <-fs.sizeChan:
fs.size = s
default:
}
return fs.size
} }
func (fs *NotifyFs) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) { func (fs *NotifyFs) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
if name == "" { if name == "" {
return &fuse.Attr{Mode: fuse.S_IFDIR | 0755}, fuse.OK return &fuse.Attr{Mode: fuse.S_IFDIR | 0755}, fuse.OK
} }
if name == "file" || (name == "dir/file" && fs.exist) { if name == "file" || (name == "dir/file" && fs.Exists()) {
return &fuse.Attr{Mode: fuse.S_IFREG | 0644, Size: fs.size}, fuse.OK return &fuse.Attr{Mode: fuse.S_IFREG | 0644, Size: fs.Size()}, fuse.OK
} }
if name == "dir" { if name == "dir" {
return &fuse.Attr{Mode: fuse.S_IFDIR | 0755}, fuse.OK return &fuse.Attr{Mode: fuse.S_IFDIR | 0755}, fuse.OK
...@@ -47,7 +73,7 @@ type NotifyTest struct { ...@@ -47,7 +73,7 @@ type NotifyTest struct {
func NewNotifyTest(t *testing.T) *NotifyTest { func NewNotifyTest(t *testing.T) *NotifyTest {
me := &NotifyTest{} me := &NotifyTest{}
me.fs = &NotifyFs{FileSystem: pathfs.NewDefaultFileSystem()} me.fs = newNotifyFs()
var err error var err error
me.dir, err = ioutil.TempDir("", "go-fuse-notify_test") me.dir, err = ioutil.TempDir("", "go-fuse-notify_test")
if err != nil { if err != nil {
...@@ -85,8 +111,7 @@ func TestInodeNotify(t *testing.T) { ...@@ -85,8 +111,7 @@ func TestInodeNotify(t *testing.T) {
fs := test.fs fs := test.fs
dir := test.dir dir := test.dir
fs.size = 42 fs.sizeChan <- 42
test.state.ThreadSanitizerSync()
fi, err := os.Lstat(dir + "/file") fi, err := os.Lstat(dir + "/file")
if err != nil { if err != nil {
...@@ -96,8 +121,7 @@ func TestInodeNotify(t *testing.T) { ...@@ -96,8 +121,7 @@ func TestInodeNotify(t *testing.T) {
t.Error(fi) t.Error(fi)
} }
test.state.ThreadSanitizerSync() fs.sizeChan <- 666
fs.size = 666
fi, err = os.Lstat(dir + "/file") fi, err = os.Lstat(dir + "/file")
if err != nil { if err != nil {
...@@ -126,9 +150,8 @@ func TestEntryNotify(t *testing.T) { ...@@ -126,9 +150,8 @@ func TestEntryNotify(t *testing.T) {
defer test.Clean() defer test.Clean()
dir := test.dir dir := test.dir
test.fs.size = 42 test.fs.sizeChan <- 42
test.fs.exist = false test.fs.existChan <- false
test.state.ThreadSanitizerSync()
fn := dir + "/dir/file" fn := dir + "/dir/file"
fi, _ := os.Lstat(fn) fi, _ := os.Lstat(fn)
...@@ -136,8 +159,7 @@ func TestEntryNotify(t *testing.T) { ...@@ -136,8 +159,7 @@ func TestEntryNotify(t *testing.T) {
t.Errorf("File should not exist, %#v", fi) t.Errorf("File should not exist, %#v", fi)
} }
test.fs.exist = true test.fs.existChan <- true
test.state.ThreadSanitizerSync()
fi, _ = os.Lstat(fn) fi, _ = os.Lstat(fn)
if fi != nil { if fi != nil {
t.Errorf("negative entry should have been cached: %#v", fi) t.Errorf("negative entry should have been cached: %#v", fi)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment