From 0d1c8342fcec1c0e2ff5ae2e460fdaf908fd2188 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Tue, 8 Nov 2022 21:43:19 +0100 Subject: [PATCH] Remove TestInotifyNoBlockingSyscalls (#532) This test checks if no additional OS threads are created; this was added after the old epoll-based inotify code was removed (which would create additional threads). It's always been a bit flaky: it currently already runs the test twice and "fails" only if both fail. We don't really control the Go scheduler and when it creates/destroys OS threads, or have all that much insight in it (the "threadcreate" profile in pprof has been broken for years). I tried to make this test a bit more reliable a few months ago, and the run-it-twice "solution" was the best I could come up. It still causes some failures though; see the links below. I don't know why it consistently fails on armle (and not e.g. arm64), but that seems a Go thing, rather than a fsnotify thing. I'm not sure if this test adds all that much value; I don't really foresee a regression where we accidentally create more OS threads than we should. Fixes #531 Also see: https://bugs.launchpad.net/ubuntu/+source/golang-fsnotify/+bug/1971967 --- backend_inotify_test.go | 52 ----------------------------------------- 1 file changed, 52 deletions(-) diff --git a/backend_inotify_test.go b/backend_inotify_test.go index f0806f0..c857291 100644 --- a/backend_inotify_test.go +++ b/backend_inotify_test.go @@ -5,7 +5,6 @@ package fsnotify import ( "errors" - "fmt" "os" "strconv" "strings" @@ -14,57 +13,6 @@ import ( "time" ) -// Make sure there are no additional threads being created. -// -// TODO: should generalize this and run for all backends. -func TestInotifyNoBlockingSyscalls(t *testing.T) { - test := func() error { - getThreads := func() (int, error) { - // return pprof.Lookup("threadcreate").Count() - d := fmt.Sprintf("/proc/%d/task", os.Getpid()) - ls, err := os.ReadDir(d) - if err != nil { - return 0, fmt.Errorf("reading %q: %s", d, err) - } - return len(ls), nil - } - - w := newWatcher(t) - start, err := getThreads() - if err != nil { - return err - } - - // Call readEvents a bunch of times; if this function has a blocking raw - // syscall, it'll create many new kthreads - for i := 0; i <= 60; i++ { - go w.readEvents() - } - - time.Sleep(2 * time.Second) - - end, err := getThreads() - if err != nil { - return err - } - if diff := end - start; diff > 0 { - return fmt.Errorf("Got a nonzero diff %v. starting: %v. ending: %v", diff, start, end) - } - return nil - } - - // This test can be a bit flaky, so run it twice and consider it "failed" - // only if both fail. - err := test() - if err != nil { - time.Sleep(2 * time.Second) - err := test() - if err != nil { - t.Fatal(err) - } - } -} - // Ensure that the correct error is returned on overflows. func TestInotifyOverflow(t *testing.T) { t.Parallel() -- 2.50.1