From b58ee27c6635712ecf59e516f67196af86c9f614 Mon Sep 17 00:00:00 2001 From: Nino Khodabandeh Date: Fri, 8 Apr 2016 11:47:25 -0700 Subject: [PATCH] Fixes race in test - Enabled race flag in the make file to alway run with -race locally - Moved polling interval into TestMain to avoid race --- Makefile | 2 +- tail_test.go | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 9ac927d..6591b24 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ default: test test: *.go - go test -v ./... + go test -v -race ./... fmt: gofmt -w . diff --git a/tail_test.go b/tail_test.go index 3beba4f..6d602a4 100644 --- a/tail_test.go +++ b/tail_test.go @@ -25,6 +25,13 @@ func init() { } } +func TestMain(m *testing.M) { + // Use a smaller poll duration for faster test runs. Keep it below + // 100ms (which value is used as common delays for tests) + watch.POLL_DURATION = 5 * time.Millisecond + os.Exit(m.Run()) +} + func TestMustExist(t *testing.T) { tail, err := TailFile("/no/such/file", Config{Follow: true, MustExist: true}) if err == nil { @@ -387,10 +394,6 @@ func NewTailTest(name string, t *testing.T) TailTest { tt.Fatal(err) } - // Use a smaller poll duration for faster test runs. Keep it below - // 100ms (which value is used as common delays for tests) - watch.POLL_DURATION = 5 * time.Millisecond - return tt }