From dcfd9ba11f1ff17fdab87761ab88ab68d7783a85 Mon Sep 17 00:00:00 2001 From: Bin Shi <39923490+binshi-bing@users.noreply.github.com> Date: Thu, 27 Apr 2023 22:41:53 -0700 Subject: [PATCH] tests: fix Flaky TestMicroserviceTSOServer/TestConcurrentlyReset (#6396) close tikv/pd#6385 Get a copy of now then call base.add, because now is shared by all goroutines and now.add() will add to itself which isn't atomic and multi-goroutine safe. Signed-off-by: Bin Shi --- tests/integrations/tso/server_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/integrations/tso/server_test.go b/tests/integrations/tso/server_test.go index c9c978e7d7f..96fc5d334b0 100644 --- a/tests/integrations/tso/server_test.go +++ b/tests/integrations/tso/server_test.go @@ -154,7 +154,10 @@ func (suite *tsoServerTestSuite) TestConcurrentlyReset() { go func() { defer wg.Done() for j := 0; j <= 100; j++ { - physical := now.Add(time.Duration(2*j)*time.Minute).UnixNano() / int64(time.Millisecond) + // Get a copy of now then call base.add, because now is shared by all goroutines + // and now.add() will add to itself which isn't atomic and multi-goroutine safe. + base := now + physical := base.Add(time.Duration(2*j)*time.Minute).UnixNano() / int64(time.Millisecond) ts := uint64(physical << 18) suite.resetTS(ts, false, false) }