Skip to content

Commit 677391f

Browse files
committed
Fix race in test
1 parent 46f296e commit 677391f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

core/connection/manager_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,16 +398,24 @@ func (tc *testContext) TestReconnectDueToPriceDrop() {
398398
}
399399
tc.connManager.priceCheckInterval = time.Millisecond
400400

401-
err := tc.connManager.Connect(consumerID, hermesID, activeProposalLookup, ConnectParams{})
401+
mux := sync.RWMutex{}
402+
proposalLookup := func() (proposal *proposal.PricedServiceProposal, err error) {
403+
mux.RLock()
404+
defer mux.RUnlock()
405+
return &activeProposal, nil
406+
}
407+
408+
err := tc.connManager.Connect(consumerID, hermesID, proposalLookup, ConnectParams{})
402409
assert.NoError(tc.T(), err)
403410
assert.Equal(tc.T(), connectionstate.Connected, tc.connManager.Status().State)
404411

405412
newPrice := market.Price{
406413
PricePerHour: big.NewInt(1),
407414
PricePerGiB: big.NewInt(1),
408415
}
409-
416+
mux.Lock()
410417
activeProposal.Price = newPrice
418+
mux.Unlock()
411419

412420
waitABit()
413421

0 commit comments

Comments
 (0)