]> go.fuhry.dev Git - fsnotify.git/commitdiff
Remove file immediately in TestWatchStress (#545)
authorMartin Tournoij <martin@arp242.net>
Sat, 14 Jan 2023 19:37:03 +0000 (20:37 +0100)
committerGitHub <noreply@github.com>
Sat, 14 Jan 2023 19:37:03 +0000 (20:37 +0100)
Previously it would create all the files and then remove it; remove the
file immediately instead.

My /tmp has ~500k free inodes and it will try to create >1 million
files, so it will error out on that.

fsnotify_test.go
helpers_test.go

index bfda80bfde62d0c9ac31d1ca066df54156043b27..61070b3d9e5703ff9871713e5af2090c733960b5 100644 (file)
@@ -1401,9 +1401,6 @@ func TestWatchStress(t *testing.T) {
                        }
                }
 
-               for i := 0; i < numFiles; i++ {
-                       rm(t, tmp, prefix+fmtNum(i), noWait)
-               }
                close(done)
        }()
        <-done
index 24f00299fa95e009da6039487f812fe0673b5291..6ebf2ea142718709f0af639aa6fa1615b0585dc5 100644 (file)
@@ -105,7 +105,8 @@ func createFiles(t *testing.T, dir, prefix string, n int, d time.Duration) int {
                        t.Logf("createFiles: stopped at %s files because it took longer than %s", fmtNum(created), d)
                        return created
                default:
-                       fp, err := os.Create(join(dir, prefix+fmtNum(i)))
+                       path := join(dir, prefix+fmtNum(i))
+                       fp, err := os.Create(path)
                        if err != nil {
                                t.Errorf("create failed for %s: %s", fmtNum(i), err)
                                continue
@@ -113,6 +114,9 @@ func createFiles(t *testing.T, dir, prefix string, n int, d time.Duration) int {
                        if err := fp.Close(); err != nil {
                                t.Errorf("close failed for %s: %s", fmtNum(i), err)
                        }
+                       if err := os.Remove(path); err != nil {
+                               t.Errorf("remove failed for %s: %s", fmtNum(i), err)
+                       }
                        if i%10_000 == 0 {
                                t.Logf("createFiles: %s", fmtNum(i))
                        }