diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-09-10 16:11:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-10 16:11:10 +0800 |
commit | 2439f49063d8498eadf26d4fa1220c5eac8412a8 (patch) | |
tree | 1142ad5a5e4393315f956324191ddb7e03b804c3 /integration_test | |
parent | 2b5c97e53e9734dda971456ff483bf2b34f0f021 (diff) | |
download | tangerine-consensus-2439f49063d8498eadf26d4fa1220c5eac8412a8.tar tangerine-consensus-2439f49063d8498eadf26d4fa1220c5eac8412a8.tar.gz tangerine-consensus-2439f49063d8498eadf26d4fa1220c5eac8412a8.tar.bz2 tangerine-consensus-2439f49063d8498eadf26d4fa1220c5eac8412a8.tar.lz tangerine-consensus-2439f49063d8498eadf26d4fa1220c5eac8412a8.tar.xz tangerine-consensus-2439f49063d8498eadf26d4fa1220c5eac8412a8.tar.zst tangerine-consensus-2439f49063d8498eadf26d4fa1220c5eac8412a8.zip |
test: add transport layer (#97)
The purpose of transport layer is to abstract the way to send messages and setup connections between peers in a p2p network. The peer discovery is simulated by a hosted server: every peer sends its address to a known server. Once collecting enough peers, respond the whole peers lists to all peers.
Changes:
- Add test.Trasnport interface
- Add test.Transport implementation by golang channel.
- Add test.transport implementation by TCP connection.
- Move LatencyModel to core/test package
- Add Marshaller interface
Diffstat (limited to 'integration_test')
-rw-r--r-- | integration_test/latency.go | 54 | ||||
-rw-r--r-- | integration_test/non-byzantine_test.go | 4 | ||||
-rw-r--r-- | integration_test/stats_test.go | 4 | ||||
-rw-r--r-- | integration_test/utils.go | 2 | ||||
-rw-r--r-- | integration_test/validator.go | 8 |
5 files changed, 9 insertions, 63 deletions
diff --git a/integration_test/latency.go b/integration_test/latency.go deleted file mode 100644 index 8f06084..0000000 --- a/integration_test/latency.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2018 The dexon-consensus-core Authors -// This file is part of the dexon-consensus-core library. -// -// The dexon-consensus-core library is free software: you can redistribute it -// and/or modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation, either version 3 of the License, -// or (at your option) any later version. -// -// The dexon-consensus-core library is distributed in the hope that it will be -// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser -// General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the dexon-consensus-core library. If not, see -// <http://www.gnu.org/licenses/>. - -package integration - -import ( - "math/rand" - "time" -) - -// LatencyModel defines an interface to randomly decide latency -// for one operation. -type LatencyModel interface { - Delay() time.Duration -} - -// NormalLatencyModel would return latencies in normal distribution. -type NormalLatencyModel struct { - Sigma float64 - Mean float64 -} - -// Delay implements LatencyModel interface. -func (m *NormalLatencyModel) Delay() time.Duration { - delay := rand.NormFloat64()*m.Sigma + m.Mean - if delay < 0 { - delay = m.Sigma / 2 - } - return time.Duration(delay) * time.Millisecond -} - -// FixedLatencyModel return fixed latencies. -type FixedLatencyModel struct { - Latency float64 -} - -// Delay implements LatencyModel interface. -func (m *FixedLatencyModel) Delay() time.Duration { - return time.Duration(m.Latency) * time.Millisecond -} diff --git a/integration_test/non-byzantine_test.go b/integration_test/non-byzantine_test.go index 827d2ad..afda9b4 100644 --- a/integration_test/non-byzantine_test.go +++ b/integration_test/non-byzantine_test.go @@ -33,11 +33,11 @@ type NonByzantineTestSuite struct { func (s *NonByzantineTestSuite) TestNonByzantine() { var ( - networkLatency = &NormalLatencyModel{ + networkLatency = &test.NormalLatencyModel{ Sigma: 20, Mean: 250, } - proposingLatency = &NormalLatencyModel{ + proposingLatency = &test.NormalLatencyModel{ Sigma: 30, Mean: 500, } diff --git a/integration_test/stats_test.go b/integration_test/stats_test.go index e0be126..8816e8c 100644 --- a/integration_test/stats_test.go +++ b/integration_test/stats_test.go @@ -16,8 +16,8 @@ func (s *EventStatsTestSuite) TestCalculate() { // Setup a test with fixed latency in proposing and network, // and make sure the calculated statistics is expected. var ( - networkLatency = &FixedLatencyModel{Latency: 100} - proposingLatency = &FixedLatencyModel{Latency: 300} + networkLatency = &test.FixedLatencyModel{Latency: 100} + proposingLatency = &test.FixedLatencyModel{Latency: 300} req = s.Require() ) diff --git a/integration_test/utils.go b/integration_test/utils.go index c1eafb7..7371223 100644 --- a/integration_test/utils.go +++ b/integration_test/utils.go @@ -10,7 +10,7 @@ import ( // PrepareValidators setups validators for testing. func PrepareValidators( validatorCount int, - networkLatency, proposingLatency LatencyModel) ( + networkLatency, proposingLatency test.LatencyModel) ( apps map[types.ValidatorID]*test.App, dbs map[types.ValidatorID]blockdb.BlockDatabase, validators map[types.ValidatorID]*Validator, diff --git a/integration_test/validator.go b/integration_test/validator.go index bfe517f..5909b46 100644 --- a/integration_test/validator.go +++ b/integration_test/validator.go @@ -68,8 +68,8 @@ type Validator struct { chainID uint32 cons *core.Consensus gov core.Governance - networkLatency LatencyModel - proposingLatency LatencyModel + networkLatency test.LatencyModel + proposingLatency test.LatencyModel } // NewValidator constructs an instance of Validator. @@ -79,8 +79,8 @@ func NewValidator( db blockdb.BlockDatabase, privateKey crypto.PrivateKey, vID types.ValidatorID, - networkLatency LatencyModel, - proposingLatency LatencyModel) *Validator { + networkLatency test.LatencyModel, + proposingLatency test.LatencyModel) *Validator { hashes := make(common.Hashes, 0) for vID := range gov.GetValidatorSet() { |