mesh-knowledge tests: set the local zone once before any goroutine, not under a running bus server (race found by the repository check on #237)
inZone wrote time.Local while the bus test's nats server read it from a goroutine that outlives its test; the race detector the repository check now runs failed TestAReviewOwedOutlivesARestartAndItsLastTryIsSaid.
This commit is contained in:
@@ -40,6 +40,9 @@ func TestMain(m *testing.M) {
|
|||||||
serve(k, os.Getenv("MESH_KNOWLEDGE_STATUS"))
|
serve(k, os.Getenv("MESH_KNOWLEDGE_STATUS"))
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
// Every test runs in a zone that is not UTC, so a time said locally is proven to be, wherever the tests run. It
|
||||||
|
// is set once, before any goroutine starts: a test that set it while a bus test's server read it raced.
|
||||||
|
time.Local = testZone
|
||||||
code := m.Run()
|
code := m.Run()
|
||||||
stopPostgres()
|
stopPostgres()
|
||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
|
|||||||
@@ -155,13 +155,16 @@ func TestProposedAgainAfterTheLastTryClearsTheNotice(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// inZone sets the local zone to one that is not UTC for one test, so a time said locally is proven to be, wherever
|
// testZone is the local zone every test runs in, set once by TestMain: not UTC.
|
||||||
// the test runs.
|
var testZone = time.FixedZone("CEST", 2*60*60)
|
||||||
|
|
||||||
|
// inZone says the test needs the local zone not to be UTC; TestMain set it before any goroutine started. Setting it
|
||||||
|
// here, under a running bus server's goroutines, was a data race the race detector failed.
|
||||||
func inZone(t *testing.T) {
|
func inZone(t *testing.T) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
was := time.Local
|
if time.Local != testZone {
|
||||||
time.Local = time.FixedZone("CEST", 2*60*60)
|
t.Fatal("the local zone is not the tests' own: TestMain sets it")
|
||||||
t.Cleanup(func() { time.Local = was })
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// novox/hq issue 497: a clear the operator's channel refused keeps its notice as told, and is sent again at the next
|
// novox/hq issue 497: a clear the operator's channel refused keeps its notice as told, and is sent again at the next
|
||||||
|
|||||||
Reference in New Issue
Block a user