diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-08-21 16:43:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-21 16:43:37 +0800 |
commit | 2c816b5d636b8f7decd234582470a3d4c6b4a93a (patch) | |
tree | 5eff9d5f035dda8e3b2632ecce41f3c192e90f21 /integration_test/utils.go | |
parent | e8f99372159a89fb3128b870de1733a4777a5144 (diff) | |
download | tangerine-consensus-2c816b5d636b8f7decd234582470a3d4c6b4a93a.tar tangerine-consensus-2c816b5d636b8f7decd234582470a3d4c6b4a93a.tar.gz tangerine-consensus-2c816b5d636b8f7decd234582470a3d4c6b4a93a.tar.bz2 tangerine-consensus-2c816b5d636b8f7decd234582470a3d4c6b4a93a.tar.lz tangerine-consensus-2c816b5d636b8f7decd234582470a3d4c6b4a93a.tar.xz tangerine-consensus-2c816b5d636b8f7decd234582470a3d4c6b4a93a.tar.zst tangerine-consensus-2c816b5d636b8f7decd234582470a3d4c6b4a93a.zip |
simulation: add simulation with scheduler (#71)
- Add new field in test.Event: HistoryIndex
HistoryIndex allow us to access them by their position in event history.
- Record local time in test.App when receiving events.
- Add statisitics module for slices of test.Event.
- add new command line utility *dexcon-simulation-with-scheduler
to verify the execution time of core.Consensus.
Diffstat (limited to 'integration_test/utils.go')
-rw-r--r-- | integration_test/utils.go | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/integration_test/utils.go b/integration_test/utils.go new file mode 100644 index 0000000..c1eafb7 --- /dev/null +++ b/integration_test/utils.go @@ -0,0 +1,72 @@ +package integration + +import ( + "github.com/dexon-foundation/dexon-consensus-core/blockdb" + "github.com/dexon-foundation/dexon-consensus-core/core/test" + "github.com/dexon-foundation/dexon-consensus-core/core/types" + "github.com/dexon-foundation/dexon-consensus-core/crypto" +) + +// PrepareValidators setups validators for testing. +func PrepareValidators( + validatorCount int, + networkLatency, proposingLatency LatencyModel) ( + apps map[types.ValidatorID]*test.App, + dbs map[types.ValidatorID]blockdb.BlockDatabase, + validators map[types.ValidatorID]*Validator, + err error) { + + var ( + db blockdb.BlockDatabase + key crypto.PrivateKey + ) + + apps = make(map[types.ValidatorID]*test.App) + dbs = make(map[types.ValidatorID]blockdb.BlockDatabase) + validators = make(map[types.ValidatorID]*Validator) + + gov, err := test.NewGovernance(validatorCount, 700) + if err != nil { + return + } + for vID := range gov.GetValidatorSet() { + apps[vID] = test.NewApp() + + if db, err = blockdb.NewMemBackedBlockDB(); err != nil { + return + } + dbs[vID] = db + } + for vID := range gov.GetValidatorSet() { + if key, err = gov.GetPrivateKey(vID); err != nil { + return + } + validators[vID] = NewValidator( + apps[vID], + gov, + dbs[vID], + key, + vID, + networkLatency, + proposingLatency) + } + return +} + +// VerifyApps is a helper to check delivery between test.Apps +func VerifyApps(apps map[types.ValidatorID]*test.App) (err error) { + for vFrom, fromApp := range apps { + if err = fromApp.Verify(); err != nil { + return + } + for vTo, toApp := range apps { + if vFrom == vTo { + continue + } + if err = fromApp.Compare(toApp); err != nil { + return + } + } + } + return +} |