소스 검색

daemon/logger/BenchmarkCopy: don't call t.Fatal from a goroutine

staticcheck go linter says:

> daemon/logger/copier_test.go:451:2: SA2002: the goroutine calls T.Fatal, which must be called in the same goroutine as the test (staticcheck)

What it doesn't say is why. The reason is, t.Fatal() calls t.FailNow(),
which is expected to stop test execution right now. It does so by
calling runtime.Goexit(), which, unless called from a main goroutine,
does not stop test execution.

Anyway, long story short, if we don't care much about stopping the test
case immediately, we can just replace t.Fatalf() with t.Errorf() which
still marks the test case as failed, but won't stop it immediately.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Kir Kolyshkin 6 년 전
부모
커밋
7b6201f032
1개의 변경된 파일2개의 추가작업 그리고 3개의 파일을 삭제
  1. 2 3
      daemon/logger/copier_test.go

+ 2 - 3
daemon/logger/copier_test.go

@@ -3,7 +3,6 @@ package logger // import "github.com/docker/docker/daemon/logger"
 import (
 	"bytes"
 	"encoding/json"
-	"fmt"
 	"io"
 	"os"
 	"strings"
@@ -453,9 +452,9 @@ func piped(b *testing.B, iterations int, delay time.Duration, buf []byte) io.Rea
 			time.Sleep(delay)
 			if n, err := w.Write(buf); err != nil || n != len(buf) {
 				if err != nil {
-					b.Fatal(err)
+					b.Error(err)
 				}
-				b.Fatal(fmt.Errorf("short write"))
+				b.Error("short write")
 			}
 		}
 		w.Close()