From 2c816b5d636b8f7decd234582470a3d4c6b4a93a Mon Sep 17 00:00:00 2001 From: Mission Liao Date: Tue, 21 Aug 2018 16:43:37 +0800 Subject: 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. --- integration_test/utils.go | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 integration_test/utils.go (limited to 'integration_test/utils.go') 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 +} -- cgit v1.2.3