diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-02 17:07:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-02 17:07:05 +0800 |
commit | 0382bbafbee5ffb820b9d31f7cfe8f6a48968a48 (patch) | |
tree | 3140508a5528d73e4cf4cca145800dfa3ba7ed7a /core/blockchain_test.go | |
parent | 35f3fe0b857e8006de345505d7fc09c0b7c10326 (diff) | |
download | tangerine-consensus-0382bbafbee5ffb820b9d31f7cfe8f6a48968a48.tar tangerine-consensus-0382bbafbee5ffb820b9d31f7cfe8f6a48968a48.tar.gz tangerine-consensus-0382bbafbee5ffb820b9d31f7cfe8f6a48968a48.tar.bz2 tangerine-consensus-0382bbafbee5ffb820b9d31f7cfe8f6a48968a48.tar.lz tangerine-consensus-0382bbafbee5ffb820b9d31f7cfe8f6a48968a48.tar.xz tangerine-consensus-0382bbafbee5ffb820b9d31f7cfe8f6a48968a48.tar.zst tangerine-consensus-0382bbafbee5ffb820b9d31f7cfe8f6a48968a48.zip |
core: optimize message handle (#542)
* core: optimize for handling agremenet result
* core: disable clone vote
* core: touch npks
Diffstat (limited to 'core/blockchain_test.go')
-rw-r--r-- | core/blockchain_test.go | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/core/blockchain_test.go b/core/blockchain_test.go index d64c2a1..ea604a2 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -19,6 +19,7 @@ package core import ( "fmt" + "math/rand" "testing" "time" @@ -175,13 +176,16 @@ func (s *BlockChainTestSuite) newRoundOneInitBlock() *types.Block { } func (s *BlockChainTestSuite) baseConcurrentAceessTest(initBlock *types.Block, - blocks []*types.Block, rands []*types.AgreementResult) { + blocks []*types.Block, results []*types.AgreementResult) { var ( bc = s.newBlockChain(initBlock, uint64(len(blocks)+1)) start = make(chan struct{}) newNotif = make(chan struct{}, 1) delivered []*types.Block ) + resultsCopy := make([]*types.AgreementResult, len(results)) + copy(resultsCopy, results) + type randomnessResult types.AgreementResult add := func(v interface{}) { <-start switch val := v.(type) { @@ -192,9 +196,13 @@ func (s *BlockChainTestSuite) baseConcurrentAceessTest(initBlock *types.Block, } case *types.AgreementResult: if err := bc.processAgreementResult(val); err != nil { - // Never assertion in sub routine when testing. - panic(err) + if err != ErrSkipButNoError { + // Never assertion in sub routine when testing. + panic(err) + } } + case *randomnessResult: + bc.addBlockRandomness(val.Position, val.Randomness) default: panic(fmt.Errorf("unknown type: %v", v)) } @@ -203,12 +211,26 @@ func (s *BlockChainTestSuite) baseConcurrentAceessTest(initBlock *types.Block, default: } } + rand.Shuffle(len(resultsCopy), func(i, j int) { + resultsCopy[i], resultsCopy[j] = resultsCopy[j], resultsCopy[i] + }) for _, b := range blocks { go add(b) } - for _, r := range rands { - go add(r) + for i, r := range resultsCopy { + if i >= len(resultsCopy)/2 { + break + } + go add((*randomnessResult)(r)) } + go func() { + for i, a := range resultsCopy { + if i < len(resultsCopy)/2 { + continue + } + add(a) + } + }() close(start) for { select { @@ -257,10 +279,7 @@ func (s *BlockChainTestSuite) TestBasicUsage() { s.Require().NoError(bc.addBlock(b0)) extracted := bc.extractBlocks() s.Require().Len(extracted, 4) - bc.pendingRandomnesses[b4.Position] = &types.AgreementResult{ - BlockHash: b4.Hash, - Randomness: common.GenerateRandomBytes(), - } + bc.pendingRandomnesses[b4.Position] = common.GenerateRandomBytes() extracted = bc.extractBlocks() s.Require().Len(extracted, 2) s.Require().Equal(extracted[0].Hash, b4.Hash) |