Skip to content

Commit

Permalink
Fix the concurrent writes to map error
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Jun 18, 2019
1 parent c68db44 commit 647a891
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/dmsg/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func TestServer_Serve(t *testing.T) {
// channel to listen for `Accept` errors. Any single error must
// fail the test
acceptErrs := make(chan error, totalRemoteTpsCount)
var remotesTpsMX sync.Mutex
remotesTps := make(map[int][]transport.Transport, len(usedRemotes))
var remotesWG sync.WaitGroup
remotesWG.Add(totalRemoteTpsCount)
Expand All @@ -359,7 +360,9 @@ func TestServer_Serve(t *testing.T) {
}

// store transport
remotesTpsMX.Lock()
remotesTps[remoteInd] = append(remotesTps[remoteInd], transport)
remotesTpsMX.Unlock()

remotesWG.Done()
}(i)
Expand All @@ -370,6 +373,7 @@ func TestServer_Serve(t *testing.T) {
// channel to listen for `Dial` errors. Any single error must
// fail the test
dialErrs := make(chan error, initiatorsCount)
var initiatorsTpsMx sync.Mutex
initiatorsTps := make([]transport.Transport, 0, initiatorsCount)
var initiatorsWG sync.WaitGroup
initiatorsWG.Add(initiatorsCount)
Expand All @@ -388,7 +392,9 @@ func TestServer_Serve(t *testing.T) {
}

// store transport
initiatorsTpsMx.Lock()
initiatorsTps = append(initiatorsTps, transport)
initiatorsTpsMx.Unlock()

initiatorsWG.Done()
}(i)
Expand Down

0 comments on commit 647a891

Please sign in to comment.