Skip to content

Commit

Permalink
Halt tests on 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 Apr 2, 2024
1 parent 8e25874 commit d9aca9f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
14 changes: 10 additions & 4 deletions ci/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ func TestWithCoverage() error {
if err != nil {
return err
}
args := append([]string{"test", "-race", "-timeout", "5m", "-cover", "-coverprofile", "coverage.txt", "-covermode", "atomic"}, packages...)
return sh.RunV("go", args...)
args := append([]string{"test", "-race", "-count=1", "-timeout", "5m", "-cover", "-coverprofile", "coverage.txt", "-covermode", "atomic"}, packages...)

env := make(map[string]string)
env["GORACE"] = "halt_on_error=1"
return sh.RunWith(env, "go", args...)
}

// Test runs unit tests
Expand All @@ -39,8 +42,11 @@ func Test() error {
if err != nil {
return err
}
args := append([]string{"test", "-race", "-count=1", "-timeout", "5m"}, packages...)
return sh.RunV("go", args...)
args := append([]string{"test", "-race", "-timeout", "5m"}, packages...)

env := make(map[string]string)
env["GORACE"] = "halt_on_error=1"
return sh.RunWith(env, "go", args...)
}

func unitTestPackages() ([]string, error) {
Expand Down
55 changes: 29 additions & 26 deletions session/pingpong/consumer_balance_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,34 +364,37 @@ func TestConsumerBalanceTracker_InprogressUnregisteredBalanceReturnedWhenNoBount
}

func TestConsumerBalanceTracker_RecoverGrandTotalPromisedSettledIsBiggerThanPromissedNotOffChain(t *testing.T) {
id1 := identity.FromAddress("0x000000001")
grandTotalPromised := big.NewInt(10)
settledAmount := big.NewInt(11)
bus := eventbus.New()
mcts := NewConsumerTotalsStorage(bus)
bc := mockConsumerBalanceChecker{}
cfg := defaultCfg
cfg.LongSync.Interval = time.Millisecond * 300
calc := newMockAddressProvider()
calc.addrToReturn = id1.ToCommonAddress()
mockBlockchainProvider := &mockBlockchainInfoProvider{}

mockBlockchainProvider.AddConsumerChannelsHermes(1, id1.ToCommonAddress(), client.ConsumersHermes{
Settled: big.NewInt(6),
})
// make data race more likely to happen
for i := 0; i < 10; i++ {
id1 := identity.FromAddress("0x000000001")
grandTotalPromised := big.NewInt(10)
settledAmount := big.NewInt(11)
bus := eventbus.New()
mcts := NewConsumerTotalsStorage(bus)
bc := mockConsumerBalanceChecker{}
cfg := defaultCfg
cfg.LongSync.Interval = time.Millisecond * 300
calc := newMockAddressProvider()
calc.addrToReturn = id1.ToCommonAddress()
mockBlockchainProvider := &mockBlockchainInfoProvider{}

mockBlockchainProvider.AddConsumerChannelsHermes(1, id1.ToCommonAddress(), client.ConsumersHermes{
Settled: big.NewInt(6),
})

cbt := NewConsumerBalanceTracker(bus, &bc, mcts, &mockconsumerInfoGetter{grandTotalPromised, settledAmount}, &mockTransactor{}, &mockRegistrationStatusProvider{}, calc, mockBlockchainProvider, defaultCfg)
cbt := NewConsumerBalanceTracker(bus, &bc, mcts, &mockconsumerInfoGetter{grandTotalPromised, settledAmount}, &mockTransactor{}, &mockRegistrationStatusProvider{}, calc, mockBlockchainProvider, defaultCfg)

err := cbt.Subscribe(bus)
assert.NoError(t, err)
bus.Publish(identity.AppTopicIdentityUnlock, identity.AppEventIdentityUnlock{
ChainID: 1,
ID: id1,
})
assert.Eventually(t, func() bool {
savedBalance, _ := mcts.Get(1, id1, common.BigToAddress(big.NewInt(0)))
return savedBalance.Cmp(big.NewInt(6)) == 0
}, defaultWaitTime, defaultWaitInterval)
err := cbt.Subscribe(bus)
assert.NoError(t, err)
bus.Publish(identity.AppTopicIdentityUnlock, identity.AppEventIdentityUnlock{
ChainID: 1,
ID: id1,
})
assert.Eventually(t, func() bool {
savedBalance, _ := mcts.Get(1, id1, common.BigToAddress(big.NewInt(0)))
return savedBalance.Cmp(big.NewInt(6)) == 0
}, defaultWaitTime, defaultWaitInterval)
}
}

type mockConsumerBalanceChecker struct {
Expand Down

0 comments on commit d9aca9f

Please sign in to comment.