]> go.fuhry.dev Git - fsnotify.git/commitdiff
Remove TestInotifyNoBlockingSyscalls (#532)
authorMartin Tournoij <martin@arp242.net>
Tue, 8 Nov 2022 20:43:19 +0000 (21:43 +0100)
committerGitHub <noreply@github.com>
Tue, 8 Nov 2022 20:43:19 +0000 (21:43 +0100)
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

index f0806f071a06888c71c9949c517adf1798027cfa..c857291adeb89f327751d79563e20f0dac69afe1 100644 (file)
@@ -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()