Skip to content

Commit

Permalink
fuse/test: Fix TestLargeDirRead
Browse files Browse the repository at this point in the history
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: #472
Change-Id: I776866bd728479da7324878d41dc71e504efd229
  • Loading branch information
navytux authored and hanwen committed Jun 14, 2023
1 parent 238293d commit e5b7884
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fuse/test/loopback_test.go
Expand Up @@ -648,10 +648,13 @@ func TestLargeDirRead(t *testing.T) {
nameSet := make(map[string]bool)
for i := 0; i < created; i++ {
// Should vary file name length.
base := fmt.Sprintf("file%d%s", i,
base := fmt.Sprintf("file%d.%s", i,
randomLengthString(len(longname)))
name := filepath.Join(subdir, base)

if nameSet[base] {
panic(fmt.Sprintf("duplicate name %q", base))
}
nameSet[base] = true

tc.WriteFile(name, []byte("bla"), 0777)
Expand Down

0 comments on commit e5b7884

Please sign in to comment.