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) {
func TestReadDirStress(t *testing.T) {
tc := newTestCase(t, &testOptions{suppressDebug: true, attrCache: true, entryCache: true})
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
stress := func(gr int) {
......
......@@ -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) {
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{}
// 40 bytes of filename, so 110 entries overflows a
// 4096 page.
for i := 0; i < 110; i++ {
// 40 bytes of filename, so 110 entries overflows a
// 4096 page.
nm := fmt.Sprintf("file%036x", i)
want[nm] = true
if err := ioutil.WriteFile(filepath.Join(mnt, nm), []byte("hello"), 0644); err != nil {
t.Fatalf("WriteFile %q: %v", nm, err)
}
}
names, err := f.Readdirnames(-1)
if err != nil {
t.Fatalf("ReadDir: %v", err)
}
got := map[string]bool{}
for _, e := range names {
got[e] = true
}
if len(got) != len(want) {
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)
// Verify that we get the expected entries
f, err := os.Open(mnt)
if err != nil {
t.Fatalf("Open: %v", err)
}
names, err := f.Readdirnames(-1)
if err != nil {
t.Fatalf("ReadDir: %v", err)
}
f.Close()
got := map[string]bool{}
for _, e := range names {
got[e] = true
}
if len(got) != len(want) {
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