From 187120a04d5707ec9ef0294ff10bace42bf881b1 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 26 May 2020 17:16:58 +0400 Subject: [PATCH] types: remove unnecessary sort call (#4876) in TestValSetUpdatePriorityOrderTests https://app.circleci.com/pipelines/github/tendermint/tendermint/3849/workflows/6d241fc8-72a8-4a3b-b3fc-887a48518f82/jobs/114996 also, reduce the number of reactors in TestReactorBroadcastTxMessage https://app.circleci.com/pipelines/github/tendermint/tendermint/3797/workflows/935cda34-dfb3-46e9-8257-92277171c91b/jobs/114562 --- mempool/reactor_test.go | 6 +++++- types/validator_set_test.go | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/mempool/reactor_test.go b/mempool/reactor_test.go index 75b946a0e..400e47e84 100644 --- a/mempool/reactor_test.go +++ b/mempool/reactor_test.go @@ -37,7 +37,11 @@ func (ps peerState) GetHeight() int64 { // be received in the others. func TestReactorBroadcastTxMessage(t *testing.T) { config := cfg.TestConfig() - const N = 4 + // if there were more than two reactors, the order of transactions could not be + // asserted in waitForTxsOnReactors (due to transactions gossiping). If we + // replace Connect2Switches (full mesh) with a func, which connects first + // reactor to others and nothing else, this test should also pass with >2 reactors. + const N = 2 reactors := makeAndConnectReactors(config, N) defer func() { for _, r := range reactors { diff --git a/types/validator_set_test.go b/types/validator_set_test.go index 15c33930e..d17d78d1e 100644 --- a/types/validator_set_test.go +++ b/types/validator_set_test.go @@ -1232,21 +1232,21 @@ func TestValSetUpdatePriorityOrderTests(t *testing.T) { func verifyValSetUpdatePriorityOrder(t *testing.T, valSet *ValidatorSet, cfg testVSetCfg, nMaxElections int) { // Run election up to nMaxElections times, sort validators by priorities valSet.IncrementProposerPriority(tmrand.Int()%nMaxElections + 1) - origValsPriSorted := validatorListCopy(valSet.Validators) - sort.Sort(validatorsByPriority(origValsPriSorted)) // apply the changes, get the updated validators, sort by priorities applyChangesToValSet(t, nil, valSet, cfg.addedVals, cfg.updatedVals, cfg.deletedVals) - updatedValsPriSorted := validatorListCopy(valSet.Validators) - sort.Sort(validatorsByPriority(updatedValsPriSorted)) // basic checks assert.Equal(t, cfg.expectedVals, toTestValList(valSet.Validators)) verifyValidatorSet(t, valSet) // verify that the added validators have the smallest priority: - // - they should be at the beginning of valListNewPriority since it is sorted by priority + // - they should be at the beginning of updatedValsPriSorted since it is + // sorted by priority if len(cfg.addedVals) > 0 { + updatedValsPriSorted := validatorListCopy(valSet.Validators) + sort.Sort(validatorsByPriority(updatedValsPriSorted)) + addedValsPriSlice := updatedValsPriSorted[:len(cfg.addedVals)] sort.Sort(ValidatorsByVotingPower(addedValsPriSlice)) assert.Equal(t, cfg.addedVals, toTestValList(addedValsPriSlice))