richardartoul / nola

MIT License
74 stars 6 forks source link

Race condition when adding -race flag to tests #60

Closed aratz-lasa closed 1 year ago

aratz-lasa commented 1 year ago

Issue

If we run go test -race ./... from the root, it fails because it detects a race condition.

Traceback

WARNING: DATA RACE
Read at 0x00c03164a4a9 by goroutine 382:
  github.com/richardartoul/nola/virtual.NewEnvironment.func1()
      /Users/aratz/github.com/richardartoul/nola/virtual/environment.go:262 +0x1ad

Previous write at 0x00c03164a4a9 by goroutine 379:
  github.com/richardartoul/nola/virtual.(*environment).pauseHeartbeat()
      /Users/aratz/github.com/richardartoul/nola/virtual/environment.go:635 +0x4d
  github.com/richardartoul/nola/virtual.TestServerVersionIsHonored()
      /Users/aratz/github.com/richardartoul/nola/virtual/environment_test.go:790 +0x3db
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1576 +0x216
  testing.(*T).Run.func1()
      /usr/local/go/src/testing/testing.go:1629 +0x47

Goroutine 382 (running) created at:
  github.com/richardartoul/nola/virtual.NewEnvironment()
      /Users/aratz/github.com/richardartoul/nola/virtual/environment.go:256 +0xf89
  github.com/richardartoul/nola/virtual.TestServerVersionIsHonored()
      /Users/aratz/github.com/richardartoul/nola/virtual/environment_test.go:781 +0x273
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1576 +0x216
  testing.(*T).Run.func1()
      /usr/local/go/src/testing/testing.go:1629 +0x47

Goroutine 379 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:1629 +0x805
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:2036 +0x8d
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1576 +0x216
  testing.runTests()
      /usr/local/go/src/testing/testing.go:2034 +0x87c
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:1906 +0xb44
  main.main()
      _testmain.go:77 +0x2e9
==================
--- FAIL: TestServerVersionIsHonored (7.07s)
    testing.go:1446: race detected during execution of test
FAIL
FAIL    github.com/richardartoul/nola/virtual   122.174s
richardartoul commented 1 year ago

Closed by #61