diff --git a/modules/mesh-knowledge/cmd/mesh-knowledge/kit_test.go b/modules/mesh-knowledge/cmd/mesh-knowledge/kit_test.go index 570f5c5c..422a5597 100644 --- a/modules/mesh-knowledge/cmd/mesh-knowledge/kit_test.go +++ b/modules/mesh-knowledge/cmd/mesh-knowledge/kit_test.go @@ -40,6 +40,9 @@ func TestMain(m *testing.M) { serve(k, os.Getenv("MESH_KNOWLEDGE_STATUS")) 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() stopPostgres() os.Exit(code) diff --git a/modules/mesh-knowledge/cmd/mesh-knowledge/review_owed_test.go b/modules/mesh-knowledge/cmd/mesh-knowledge/review_owed_test.go index c094a35f..2454746b 100644 --- a/modules/mesh-knowledge/cmd/mesh-knowledge/review_owed_test.go +++ b/modules/mesh-knowledge/cmd/mesh-knowledge/review_owed_test.go @@ -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 -// the test runs. +// testZone is the local zone every test runs in, set once by TestMain: not UTC. +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) { t.Helper() - was := time.Local - time.Local = time.FixedZone("CEST", 2*60*60) - t.Cleanup(func() { time.Local = was }) + if time.Local != testZone { + t.Fatal("the local zone is not the tests' own: TestMain sets it") + } } // novox/hq issue 497: a clear the operator's channel refused keeps its notice as told, and is sent again at the next