Skip to content

Commit b58ee27

Browse files
author
Nino Khodabandeh
committed
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
1 parent 08067f9 commit b58ee27

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
default: test
22

33
test: *.go
4-
go test -v ./...
4+
go test -v -race ./...
55

66
fmt:
77
gofmt -w .

tail_test.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ func init() {
2525
}
2626
}
2727

28+
func TestMain(m *testing.M) {
29+
// Use a smaller poll duration for faster test runs. Keep it below
30+
// 100ms (which value is used as common delays for tests)
31+
watch.POLL_DURATION = 5 * time.Millisecond
32+
os.Exit(m.Run())
33+
}
34+
2835
func TestMustExist(t *testing.T) {
2936
tail, err := TailFile("/no/such/file", Config{Follow: true, MustExist: true})
3037
if err == nil {
@@ -387,10 +394,6 @@ func NewTailTest(name string, t *testing.T) TailTest {
387394
tt.Fatal(err)
388395
}
389396

390-
// Use a smaller poll duration for faster test runs. Keep it below
391-
// 100ms (which value is used as common delays for tests)
392-
watch.POLL_DURATION = 5 * time.Millisecond
393-
394397
return tt
395398
}
396399

0 commit comments

Comments
 (0)