Skip to content

Commit

Permalink
Fix data race in NSMgr tests (#874)
Browse files Browse the repository at this point in the history
* Fix data race in NSMgr tests

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Add missed wait

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
  • Loading branch information
Vladimir Popov authored Apr 27, 2021
1 parent 79914fd commit d96382a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/networkservice/chains/nsmgr/nsmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ func (s *nsmgrSuite) Test_Remote_ParallelUsecase() {
request := defaultRequest()
counter := &counterServer{}

var unregisterWG sync.WaitGroup
unregisterWG.Add(1)
go func() {
defer unregisterWG.Done()

time.Sleep(time.Millisecond * 100)
_, err := s.domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter)
require.NoError(t, err)
Expand Down Expand Up @@ -122,6 +126,7 @@ func (s *nsmgrSuite) Test_Remote_ParallelUsecase() {
require.Equal(t, int32(1), atomic.LoadInt32(&counter.Closes))

// Endpoint unregister
unregisterWG.Wait()
_, err = s.domain.Nodes[0].EndpointRegistryClient.Unregister(ctx, nseReg)
require.NoError(t, err)
}
Expand Down Expand Up @@ -198,7 +203,12 @@ func (s *nsmgrSuite) Test_Remote_BusyEndpointsUsecase() {
wg.Done()
}(i)
}

var unregisterWG sync.WaitGroup
unregisterWG.Add(1)
go func() {
defer unregisterWG.Done()

wg.Wait()
time.Sleep(time.Second / 2)
nsesReg[3] = defaultRegistryEndpoint()
Expand Down Expand Up @@ -231,6 +241,7 @@ func (s *nsmgrSuite) Test_Remote_BusyEndpointsUsecase() {
require.Equal(t, int32(1), atomic.LoadInt32(&counter.Closes))

// Endpoint unregister
unregisterWG.Wait()
for i := 0; i < len(nsesReg); i++ {
_, err = s.domain.Nodes[1].EndpointRegistryClient.Unregister(ctx, nsesReg[i])
require.NoError(t, err)
Expand Down

0 comments on commit d96382a

Please sign in to comment.