Commit e5b78843 authored by Kirill Smelkov's avatar Kirill Smelkov Committed by Han-Wen Nienhuys

fuse/test: Fix TestLargeDirRead

This test tries to create many files with random names and then asserts
that readdir returns so many files that it created. But the test
had a bug in that two random file names could be the same
name but accounted twice. This leads to assertion in the end that the
number of direntries read via readdir is not as expected.

Here is how two random names could turn out to be the same:

name 1: "file3" + "0" generated by randomLengthString
name 2: "file30" + "" generated by randomLengthString

-> Fix it by constructing random names guaranteed different.

Fixes: https://github.com/hanwen/go-fuse/issues/472
Change-Id: I776866bd728479da7324878d41dc71e504efd229
parent 238293d8
...@@ -648,10 +648,13 @@ func TestLargeDirRead(t *testing.T) { ...@@ -648,10 +648,13 @@ func TestLargeDirRead(t *testing.T) {
nameSet := make(map[string]bool) nameSet := make(map[string]bool)
for i := 0; i < created; i++ { for i := 0; i < created; i++ {
// Should vary file name length. // Should vary file name length.
base := fmt.Sprintf("file%d%s", i, base := fmt.Sprintf("file%d.%s", i,
randomLengthString(len(longname))) randomLengthString(len(longname)))
name := filepath.Join(subdir, base) name := filepath.Join(subdir, base)
if nameSet[base] {
panic(fmt.Sprintf("duplicate name %q", base))
}
nameSet[base] = true nameSet[base] = true
tc.WriteFile(name, []byte("bla"), 0777) tc.WriteFile(name, []byte("bla"), 0777)
......
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