From 4f94e6cd0c60cf36b3ad1d56c570ee89041c8e79 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Sat, 14 Jan 2023 20:37:03 +0100 Subject: [PATCH] Remove file immediately in TestWatchStress (#545) 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 | 3 --- helpers_test.go | 6 +++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fsnotify_test.go b/fsnotify_test.go index bfda80b..61070b3 100644 --- a/fsnotify_test.go +++ b/fsnotify_test.go @@ -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 diff --git a/helpers_test.go b/helpers_test.go index 24f0029..6ebf2ea 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -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)) } -- 2.50.1