fix: Wait check node id goroutine in case of data race (#36302)

Resolves: #36301

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2024-09-19 10:41:10 +08:00 committed by GitHub
parent e013ef1908
commit c0317ce672
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,6 +21,7 @@ import (
"flag" "flag"
"os" "os"
"strings" "strings"
"sync"
"time" "time"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
@ -104,8 +105,11 @@ func (s *MiniClusterSuite) SetupTest() {
s.Require().NoError(err) s.Require().NoError(err)
s.Cluster = c s.Cluster = c
checkWg := sync.WaitGroup{}
checkWg.Add(1)
// start mini cluster // start mini cluster
nodeIDCheckReport := func() { nodeIDCheckReport := func() {
defer checkWg.Done()
timeoutCtx, cancelFunc := context.WithTimeout(ctx, 5*time.Second) timeoutCtx, cancelFunc := context.WithTimeout(ctx, 5*time.Second)
defer cancelFunc() defer cancelFunc()
@ -124,6 +128,7 @@ func (s *MiniClusterSuite) SetupTest() {
} }
go nodeIDCheckReport() go nodeIDCheckReport()
s.Require().NoError(s.Cluster.Start()) s.Require().NoError(s.Cluster.Start())
checkWg.Wait()
} }
func (s *MiniClusterSuite) TearDownTest() { func (s *MiniClusterSuite) TearDownTest() {