Skip to content

Commit

Permalink
Merge pull request #10371 from vegaprotocol/validators-flaky-tests
Browse files Browse the repository at this point in the history
test: ensure we wait for the end of the test if needed
  • Loading branch information
EVODelavega authored Jan 11, 2024
2 parents 5a67c99 + 575e5b1 commit 835add5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pipeline {
stage('core/integration tests') {
steps {
dir('vega/core/integration') {
sh 'godog build -o core_integration.test && ./core_integration.test --format=junit:core-integration-report.xml'
sh 'go test . --godog.format=junit:core-integration-report.xml'
junit checksName: 'Core Integration Tests', testResults: 'core-integration-report.xml'
}
}
Expand Down
19 changes: 16 additions & 3 deletions core/validators/witness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func TestVoteMajorityCalculation(t *testing.T) {
erc.top.EXPECT().IsValidator().AnyTimes().Return(true)

ch := make(chan struct{}, 1)
defer close(ch)
res := testRes{"resource-id-1", func() error {
ch <- struct{}{}
return nil
Expand Down Expand Up @@ -300,7 +301,9 @@ func testOnTick(t *testing.T) {
erc.top.EXPECT().GetVotingPower(gomock.Any()).AnyTimes().Return(int64(100))
erc.top.EXPECT().IsValidator().AnyTimes().Return(true)

wg := sync.WaitGroup{}
ch := make(chan struct{}, 1)
defer close(ch)
res := testRes{"resource-id-1", func() error {
ch <- struct{}{}
return nil
Expand All @@ -318,19 +321,28 @@ func testOnTick(t *testing.T) {
<-ch

// first on chain time update, we send our own vote
erc.cmd.EXPECT().Command(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1)
wg.Add(1)
erc.cmd.EXPECT().Command(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).Do(func(_ context.Context, _ txn.Command, _ proto.Message, _ func(string, error), _ *backoff.ExponentialBackOff) {
wg.Done()
})
newNow := erc.startTime.Add(1 * time.Second)
erc.OnTick(context.Background(), newNow)

// then we propagate our own vote
pubKey := newPublicKey(selfPubKey)
erc.top.EXPECT().IsValidatorVegaPubKey(pubKey.Hex()).Times(1).Return(true)
wg.Add(1)
erc.top.EXPECT().IsValidatorVegaPubKey(pubKey.Hex()).Times(1).Return(true).Do(func(_ string) {
wg.Done()
})
err = erc.AddNodeCheck(context.Background(), &commandspb.NodeVote{Reference: res.id}, pubKey)
assert.NoError(t, err)

// second vote from another validator
othPubKey := newPublicKey("somepubkey")
erc.top.EXPECT().IsValidatorVegaPubKey(othPubKey.Hex()).Times(1).Return(true)
wg.Add(1)
erc.top.EXPECT().IsValidatorVegaPubKey(othPubKey.Hex()).Times(1).Return(true).Do(func(_ string) {
wg.Done()
})
err = erc.AddNodeCheck(context.Background(), &commandspb.NodeVote{Reference: res.id}, othPubKey)
assert.NoError(t, err)

Expand All @@ -341,6 +353,7 @@ func testOnTick(t *testing.T) {

// block to wait for the result
<-ch
wg.Wait()
}

func testOnTickNonValidator(t *testing.T) {
Expand Down

0 comments on commit 835add5

Please sign in to comment.