Skip to content

Commit

Permalink
Test service Proposal on a data race
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Litvinov <[email protected]>
  • Loading branch information
Zensey committed Mar 22, 2024
1 parent fe40a6d commit ccc77a4
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions core/service/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import (
"errors"
"net"
"sync"
"sync/atomic"
"testing"
"time"

"github.com/mysteriumnetwork/node/market"
"github.com/mysteriumnetwork/node/mocks"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -71,6 +74,46 @@ func Test_Pool_Add(t *testing.T) {
assert.Len(t, pool.instances, 1)
}

func Test_Pool_DataRace(t *testing.T) {
service := &Instance{
service: &mockService{},
eventPublisher: mocks.NewEventBus(),
location: mockLocationResolver{},
}

active := new(atomic.Bool)
active.Store(true)

var wg sync.WaitGroup

wg.Add(2)
go func() {
var location market.Location

defer wg.Done()
for i := 0; i < 100; i++ {
p := service.proposalWithCurrentLocation()
location = p.Location

time.Sleep(1 * time.Millisecond)
}
active.Store(false)
_ = location
}()
go func() {
var proposal market.ServiceProposal

defer wg.Done()
for active.Load() == true {
proposal = service.CopyProposal()

time.Sleep(1 * time.Millisecond)
}
_ = proposal
}()
wg.Wait()
}

func Test_Pool_StopAllSuccess(t *testing.T) {
instance := &Instance{
service: &mockService{},
Expand Down

0 comments on commit ccc77a4

Please sign in to comment.