]> go.fuhry.dev Git - fsnotify.git/commitdiff
fix go vet warnings: call to (*T).Fatalf from a non-test goroutine (#416)
authorIchinose Shogo <shogo82148@gmail.com>
Mon, 17 Jan 2022 14:35:07 +0000 (23:35 +0900)
committerGitHub <noreply@github.com>
Mon, 17 Jan 2022 14:35:07 +0000 (23:35 +0900)
inotify_poller_test.go
inotify_test.go
integration_test.go

index c7475454c2900a7b3691d7679ee7aa2c151104fa..110e00dbdd275cdc25a613eb68282f072fed5483 100644 (file)
@@ -179,7 +179,7 @@ func TestPollerConcurrent(t *testing.T) {
                for {
                        ok, err := poller.wait()
                        if err != nil {
-                               t.Fatalf("poller failed: %v", err)
+                               t.Errorf("poller failed: %v", err)
                        }
                        oks <- ok
                        if !<-live {
@@ -227,4 +227,8 @@ func TestPollerConcurrent(t *testing.T) {
                t.Fatalf("expected true")
        }
        tfd.get(t)
+
+       // wait for all goroutines for finish.
+       live <- false
+       <-oks
 }
index 90c82b8ef7e0fce45f0e33ec95bc01821d2e4c2a..f121c0144699922f7cadfcd98325db626d0859d9 100644 (file)
@@ -330,15 +330,17 @@ func TestInotifyInnerMapLength(t *testing.T) {
        if err != nil {
                t.Fatalf("Failed to create watcher: %v", err)
        }
-       defer w.Close()
 
        err = w.Add(testFile)
        if err != nil {
                t.Fatalf("Failed to add testFile: %v", err)
        }
+       var wg sync.WaitGroup
+       wg.Add(1)
        go func() {
+               defer wg.Done()
                for err := range w.Errors {
-                       t.Fatalf("error received: %s", err)
+                       t.Errorf("error received: %s", err)
                }
        }()
 
@@ -357,6 +359,9 @@ func TestInotifyInnerMapLength(t *testing.T) {
        if len(w.paths) != 0 {
                t.Fatalf("Expected paths len is 0, but got: %d, %v", len(w.paths), w.paths)
        }
+
+       w.Close()
+       wg.Wait()
 }
 
 func TestInotifyOverflow(t *testing.T) {
index fc09e03f78141d81d0f0c3c1d5e1173bcb54b89d..85d7b9bbe7b862b4f1e41249036f572f3ae6ffcd 100644 (file)
@@ -14,6 +14,7 @@ import (
        "path"
        "path/filepath"
        "runtime"
+       "sync"
        "sync/atomic"
        "testing"
        "time"
@@ -75,9 +76,12 @@ func TestFsnotifyMultipleOperations(t *testing.T) {
        watcher := newWatcher(t)
 
        // Receive errors on the error channel on a separate goroutine
+       var wg sync.WaitGroup
+       wg.Add(1)
        go func() {
+               defer wg.Done()
                for err := range watcher.Errors {
-                       t.Fatalf("error received: %s", err)
+                       t.Errorf("error received: %s", err)
                }
        }()
 
@@ -187,6 +191,9 @@ func TestFsnotifyMultipleOperations(t *testing.T) {
        case <-time.After(2 * time.Second):
                t.Fatal("event stream was not closed after 2 seconds")
        }
+
+       // wait for all groutines to finish.
+       wg.Wait()
 }
 
 func TestFsnotifyMultipleCreates(t *testing.T) {
@@ -837,10 +844,13 @@ func TestRemovalOfWatch(t *testing.T) {
                t.Fatalf("Could not remove the watch: %v\n", err)
        }
 
+       var wg sync.WaitGroup
+       wg.Add(1)
        go func() {
+               defer wg.Done()
                select {
                case ev := <-watcher.Events:
-                       t.Fatalf("We received event: %v\n", ev)
+                       t.Errorf("We received event: %v\n", ev)
                case <-time.After(500 * time.Millisecond):
                        t.Log("No event received, as expected.")
                }
@@ -858,7 +868,9 @@ func TestRemovalOfWatch(t *testing.T) {
        if err := os.Chmod(testFileAlreadyExists, 0700); err != nil {
                t.Fatalf("chmod failed: %s", err)
        }
-       time.Sleep(400 * time.Millisecond)
+
+       // wait for all groutines to finish.
+       wg.Wait()
 }
 
 func TestFsnotifyAttrib(t *testing.T) {