aboutsummaryrefslogtreecommitdiffstats
path: root/core/test
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-08-30 15:09:15 +0800
committerGitHub <noreply@github.com>2018-08-30 15:09:15 +0800
commit8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8 (patch)
treeb9ea30e61b410557cc87aa4d828c4cb3cf771984 /core/test
parent1f34da04eb9d80648349140eb1442cab87ba5cd8 (diff)
downloaddexon-consensus-8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8.tar
dexon-consensus-8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8.tar.gz
dexon-consensus-8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8.tar.bz2
dexon-consensus-8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8.tar.lz
dexon-consensus-8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8.tar.xz
dexon-consensus-8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8.tar.zst
dexon-consensus-8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8.zip
core: tune total ordering performance (#81)
- Replace map with slice Compared to slice, accessing to map is slower and the memory usage is inefficient.
Diffstat (limited to 'core/test')
-rw-r--r--core/test/blocks-generator.go5
-rw-r--r--core/test/blocks-generator_test.go15
-rw-r--r--core/test/revealer_test.go3
3 files changed, 15 insertions, 8 deletions
diff --git a/core/test/blocks-generator.go b/core/test/blocks-generator.go
index 3cd97ee..b05d08f 100644
--- a/core/test/blocks-generator.go
+++ b/core/test/blocks-generator.go
@@ -236,7 +236,8 @@ func (gen *BlocksGenerator) Generate(
validatorCount int,
blockCount int,
ackingCountGenerator func() int,
- writer blockdb.Writer) (err error) {
+ writer blockdb.Writer) (
+ validators types.ValidatorIDs, err error) {
if ackingCountGenerator == nil {
ackingCountGenerator = normalAckingCountGenerator(
@@ -244,7 +245,7 @@ func (gen *BlocksGenerator) Generate(
float64(validatorCount/2),
float64(validatorCount/4+1))
}
- validators := []types.ValidatorID{}
+ validators = types.ValidatorIDs{}
for i := 0; i < validatorCount; i++ {
validators = append(
validators, types.ValidatorID{Hash: common.NewRandomHash()})
diff --git a/core/test/blocks-generator_test.go b/core/test/blocks-generator_test.go
index 43e994f..5c85fbd 100644
--- a/core/test/blocks-generator_test.go
+++ b/core/test/blocks-generator_test.go
@@ -39,9 +39,10 @@ func (s *BlocksGeneratorTestCase) TestGenerate() {
db, err := blockdb.NewMemBackedBlockDB()
s.Require().Nil(err)
- err = gen.Generate(
+ validators, err := gen.Generate(
validatorCount, blockCount, nil, db)
s.Require().Nil(err)
+ s.Require().Len(validators, validatorCount)
// Load all blocks in that database for further checking.
iter, err := db.GetAll()
@@ -114,8 +115,10 @@ func (s *BlocksGeneratorTestCase) TestGenerateWithMaxAckCount() {
// Generate with 0 acks.
db, err := blockdb.NewMemBackedBlockDB()
req.Nil(err)
- req.Nil(gen.Generate(
- validatorCount, blockCount, MaxAckingCountGenerator(0), db))
+ validators, err := gen.Generate(
+ validatorCount, blockCount, MaxAckingCountGenerator(0), db)
+ req.Nil(err)
+ req.Len(validators, validatorCount)
// Load blocks to check their acking count.
iter, err := db.GetAll()
req.Nil(err)
@@ -134,9 +137,11 @@ func (s *BlocksGeneratorTestCase) TestGenerateWithMaxAckCount() {
// Generate with acks as many as possible.
db, err = blockdb.NewMemBackedBlockDB()
req.Nil(err)
- req.Nil(gen.Generate(
+ validators, err = gen.Generate(
validatorCount, blockCount, MaxAckingCountGenerator(
- validatorCount), db))
+ validatorCount), db)
+ req.Nil(err)
+ req.Len(validators, validatorCount)
// Load blocks to verify the average acking count.
totalAckingCount := 0
totalBlockCount := 0
diff --git a/core/test/revealer_test.go b/core/test/revealer_test.go
index 8087136..032cab3 100644
--- a/core/test/revealer_test.go
+++ b/core/test/revealer_test.go
@@ -45,9 +45,10 @@ func (s *RevealerTestSuite) SetupSuite() {
// Randomly generate blocks.
gen := NewBlocksGenerator(nil, stableRandomHash)
- err = gen.Generate(
+ validators, err := gen.Generate(
validatorCount, blockCount, nil, s.db)
s.Require().Nil(err)
+ s.Require().Len(validators, validatorCount)
// Cache the count of total generated block.
iter, err := s.db.GetAll()