Commit 0fb2d39e authored by Jakob Unterwurzacher's avatar Jakob Unterwurzacher

posixtest: ReadDir: check directory listing after each file

There is an unhandled corner case in the directory stream
handling. The stricter test catches it:

  go-fuse/fs$ go test
  --- FAIL: TestPosix (0.20s)
      --- FAIL: TestPosix/ReadDir (0.09s)
          test.go:342: got 19 entries, want 20
          test.go:342: got 40 entries, want 41
          test.go:342: got 61 entries, want 62
          test.go:342: got 82 entries, want 83
          test.go:342: got 103 entries, want 104
  FAIL
  exit status 1
  FAIL	github.com/hanwen/go-fuse/v2/fs	0.610s

Fix comes next.

Change-Id: I3e22904fce96bf2264ede47656ebd2936a7d13cd
parent 17c7e2cd
...@@ -196,8 +196,14 @@ func TestNotifyEntry(t *testing.T) { ...@@ -196,8 +196,14 @@ func TestNotifyEntry(t *testing.T) {
func TestReadDirStress(t *testing.T) { func TestReadDirStress(t *testing.T) {
tc := newTestCase(t, &testOptions{suppressDebug: true, attrCache: true, entryCache: true}) tc := newTestCase(t, &testOptions{suppressDebug: true, attrCache: true, entryCache: true})
defer tc.Clean() defer tc.Clean()
// (ab)use posixtest.ReadDir to create 110 test files
posixtest.ReadDir(t, tc.mntDir) // Create 110 entries
for i := 0; i < 110; i++ {
name := fmt.Sprintf("file%036x", i)
if err := ioutil.WriteFile(filepath.Join(tc.mntDir, name), []byte("hello"), 0644); err != nil {
t.Fatalf("WriteFile %q: %v", name, err)
}
}
var wg sync.WaitGroup var wg sync.WaitGroup
stress := func(gr int) { stress := func(gr int) {
......
...@@ -312,39 +312,39 @@ func RenameOverwrite(t *testing.T, mnt string, destExists bool) { ...@@ -312,39 +312,39 @@ func RenameOverwrite(t *testing.T, mnt string, destExists bool) {
} }
} }
// ReadDir creates 110 files one by one, checking that we get the expected
// entries after each file creation.
func ReadDir(t *testing.T, mnt string) { func ReadDir(t *testing.T, mnt string) {
f, err := os.Open(mnt)
if err != nil {
t.Fatalf("Open: %v", err)
}
defer f.Close()
// add entries after opening the directory
want := map[string]bool{} want := map[string]bool{}
// 40 bytes of filename, so 110 entries overflows a
// 4096 page.
for i := 0; i < 110; i++ { for i := 0; i < 110; i++ {
// 40 bytes of filename, so 110 entries overflows a
// 4096 page.
nm := fmt.Sprintf("file%036x", i) nm := fmt.Sprintf("file%036x", i)
want[nm] = true want[nm] = true
if err := ioutil.WriteFile(filepath.Join(mnt, nm), []byte("hello"), 0644); err != nil { if err := ioutil.WriteFile(filepath.Join(mnt, nm), []byte("hello"), 0644); err != nil {
t.Fatalf("WriteFile %q: %v", nm, err) t.Fatalf("WriteFile %q: %v", nm, err)
} }
} // Verify that we get the expected entries
f, err := os.Open(mnt)
names, err := f.Readdirnames(-1) if err != nil {
if err != nil { t.Fatalf("Open: %v", err)
t.Fatalf("ReadDir: %v", err) }
} names, err := f.Readdirnames(-1)
got := map[string]bool{} if err != nil {
for _, e := range names { t.Fatalf("ReadDir: %v", err)
got[e] = true }
} f.Close()
if len(got) != len(want) { got := map[string]bool{}
t.Errorf("got %d entries, want %d", len(got), len(want)) for _, e := range names {
} got[e] = true
for k := range got { }
if !want[k] { if len(got) != len(want) {
t.Errorf("got unknown name %q", k) t.Errorf("got %d entries, want %d", len(got), len(want))
}
for k := range got {
if !want[k] {
t.Errorf("got unknown name %q", k)
}
} }
} }
} }
......
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