mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
make tests run faster
This commit is contained in:
parent
1cb76625d3
commit
8171628ee5
@ -294,6 +294,7 @@ func TestP2PConfig() *P2PConfig {
|
|||||||
conf := DefaultP2PConfig()
|
conf := DefaultP2PConfig()
|
||||||
conf.ListenAddress = "tcp://0.0.0.0:36656"
|
conf.ListenAddress = "tcp://0.0.0.0:36656"
|
||||||
conf.SkipUPNP = true
|
conf.SkipUPNP = true
|
||||||
|
conf.FlushThrottleTimeout = 10
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,6 +439,8 @@ func TestConsensusConfig() *ConsensusConfig {
|
|||||||
config.TimeoutPrecommitDelta = 1
|
config.TimeoutPrecommitDelta = 1
|
||||||
config.TimeoutCommit = 10
|
config.TimeoutCommit = 10
|
||||||
config.SkipTimeoutCommit = true
|
config.SkipTimeoutCommit = true
|
||||||
|
config.PeerGossipSleepDuration = 5
|
||||||
|
config.PeerQueryMaj23SleepDuration = 50
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// genesis, chain_id, priv_val
|
// genesis, chain_id, priv_val
|
||||||
var config *cfg.Config // NOTE: must be reset for each _test.go file
|
var config *cfg.Config // NOTE: must be reset for each _test.go file
|
||||||
var ensureTimeout = time.Second * 2
|
var ensureTimeout = time.Second * 1 // must be in seconds because CreateEmptyBlocksInterval is
|
||||||
|
|
||||||
func ensureDir(dir string, mode os.FileMode) {
|
func ensureDir(dir string, mode os.FileMode) {
|
||||||
if err := cmn.EnsureDir(dir, mode); err != nil {
|
if err := cmn.EnsureDir(dir, mode); err != nil {
|
||||||
|
@ -35,7 +35,7 @@ func startConsensusNet(t *testing.T, css []*ConsensusState, N int) ([]*Consensus
|
|||||||
/*logger, err := tmflags.ParseLogLevel("consensus:info,*:error", logger, "info")
|
/*logger, err := tmflags.ParseLogLevel("consensus:info,*:error", logger, "info")
|
||||||
if err != nil { t.Fatal(err)}*/
|
if err != nil { t.Fatal(err)}*/
|
||||||
reactors[i] = NewConsensusReactor(css[i], true) // so we dont start the consensus states
|
reactors[i] = NewConsensusReactor(css[i], true) // so we dont start the consensus states
|
||||||
reactors[i].SetLogger(css[i].Logger.With("validator", "i"))
|
reactors[i].SetLogger(css[i].Logger.With("validator", "i", "module", "consensus"))
|
||||||
|
|
||||||
// eventBus is already started with the cs
|
// eventBus is already started with the cs
|
||||||
eventBuses[i] = css[i].eventBus
|
eventBuses[i] = css[i].eventBus
|
||||||
@ -83,9 +83,8 @@ func TestReactorBasic(t *testing.T) {
|
|||||||
reactors, eventChans, eventBuses := startConsensusNet(t, css, N)
|
reactors, eventChans, eventBuses := startConsensusNet(t, css, N)
|
||||||
defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses)
|
defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses)
|
||||||
// wait till everyone makes the first new block
|
// wait till everyone makes the first new block
|
||||||
timeoutWaitGroup(t, N, func(wg *sync.WaitGroup, j int) {
|
timeoutWaitGroup(t, N, func(j int) {
|
||||||
<-eventChans[j]
|
<-eventChans[j]
|
||||||
wg.Done()
|
|
||||||
}, css)
|
}, css)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,9 +105,8 @@ func TestReactorProposalHeartbeats(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
// wait till everyone sends a proposal heartbeat
|
// wait till everyone sends a proposal heartbeat
|
||||||
timeoutWaitGroup(t, N, func(wg *sync.WaitGroup, j int) {
|
timeoutWaitGroup(t, N, func(j int) {
|
||||||
<-heartbeatChans[j]
|
<-heartbeatChans[j]
|
||||||
wg.Done()
|
|
||||||
}, css)
|
}, css)
|
||||||
|
|
||||||
// send a tx
|
// send a tx
|
||||||
@ -117,9 +115,8 @@ func TestReactorProposalHeartbeats(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// wait till everyone makes the first new block
|
// wait till everyone makes the first new block
|
||||||
timeoutWaitGroup(t, N, func(wg *sync.WaitGroup, j int) {
|
timeoutWaitGroup(t, N, func(j int) {
|
||||||
<-eventChans[j]
|
<-eventChans[j]
|
||||||
wg.Done()
|
|
||||||
}, css)
|
}, css)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,9 +137,8 @@ func TestReactorVotingPowerChange(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// wait till everyone makes block 1
|
// wait till everyone makes block 1
|
||||||
timeoutWaitGroup(t, nVals, func(wg *sync.WaitGroup, j int) {
|
timeoutWaitGroup(t, nVals, func(j int) {
|
||||||
<-eventChans[j]
|
<-eventChans[j]
|
||||||
wg.Done()
|
|
||||||
}, css)
|
}, css)
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@ -203,9 +199,8 @@ func TestReactorValidatorSetChanges(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// wait till everyone makes block 1
|
// wait till everyone makes block 1
|
||||||
timeoutWaitGroup(t, nPeers, func(wg *sync.WaitGroup, j int) {
|
timeoutWaitGroup(t, nPeers, func(j int) {
|
||||||
<-eventChans[j]
|
<-eventChans[j]
|
||||||
wg.Done()
|
|
||||||
}, css)
|
}, css)
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@ -293,16 +288,13 @@ func TestReactorWithTimeoutCommit(t *testing.T) {
|
|||||||
defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses)
|
defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses)
|
||||||
|
|
||||||
// wait till everyone makes the first new block
|
// wait till everyone makes the first new block
|
||||||
timeoutWaitGroup(t, N-1, func(wg *sync.WaitGroup, j int) {
|
timeoutWaitGroup(t, N-1, func(j int) {
|
||||||
<-eventChans[j]
|
<-eventChans[j]
|
||||||
wg.Done()
|
|
||||||
}, css)
|
}, css)
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitForAndValidateBlock(t *testing.T, n int, activeVals map[string]struct{}, eventChans []chan interface{}, css []*ConsensusState, txs ...[]byte) {
|
func waitForAndValidateBlock(t *testing.T, n int, activeVals map[string]struct{}, eventChans []chan interface{}, css []*ConsensusState, txs ...[]byte) {
|
||||||
timeoutWaitGroup(t, n, func(wg *sync.WaitGroup, j int) {
|
timeoutWaitGroup(t, n, func(j int) {
|
||||||
defer wg.Done()
|
|
||||||
|
|
||||||
css[j].Logger.Debug("waitForAndValidateBlock")
|
css[j].Logger.Debug("waitForAndValidateBlock")
|
||||||
newBlockI, ok := <-eventChans[j]
|
newBlockI, ok := <-eventChans[j]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -320,8 +312,7 @@ func waitForAndValidateBlock(t *testing.T, n int, activeVals map[string]struct{}
|
|||||||
}
|
}
|
||||||
|
|
||||||
func waitForAndValidateBlockWithTx(t *testing.T, n int, activeVals map[string]struct{}, eventChans []chan interface{}, css []*ConsensusState, txs ...[]byte) {
|
func waitForAndValidateBlockWithTx(t *testing.T, n int, activeVals map[string]struct{}, eventChans []chan interface{}, css []*ConsensusState, txs ...[]byte) {
|
||||||
timeoutWaitGroup(t, n, func(wg *sync.WaitGroup, j int) {
|
timeoutWaitGroup(t, n, func(j int) {
|
||||||
defer wg.Done()
|
|
||||||
ntxs := 0
|
ntxs := 0
|
||||||
BLOCK_TX_LOOP:
|
BLOCK_TX_LOOP:
|
||||||
for {
|
for {
|
||||||
@ -352,8 +343,7 @@ func waitForAndValidateBlockWithTx(t *testing.T, n int, activeVals map[string]st
|
|||||||
}
|
}
|
||||||
|
|
||||||
func waitForBlockWithUpdatedValsAndValidateIt(t *testing.T, n int, updatedVals map[string]struct{}, eventChans []chan interface{}, css []*ConsensusState) {
|
func waitForBlockWithUpdatedValsAndValidateIt(t *testing.T, n int, updatedVals map[string]struct{}, eventChans []chan interface{}, css []*ConsensusState) {
|
||||||
timeoutWaitGroup(t, n, func(wg *sync.WaitGroup, j int) {
|
timeoutWaitGroup(t, n, func(j int) {
|
||||||
defer wg.Done()
|
|
||||||
|
|
||||||
var newBlock *types.Block
|
var newBlock *types.Block
|
||||||
LOOP:
|
LOOP:
|
||||||
@ -391,11 +381,14 @@ func validateBlock(block *types.Block, activeVals map[string]struct{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func timeoutWaitGroup(t *testing.T, n int, f func(*sync.WaitGroup, int), css []*ConsensusState) {
|
func timeoutWaitGroup(t *testing.T, n int, f func(int), css []*ConsensusState) {
|
||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
wg.Add(n)
|
wg.Add(n)
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
go f(wg, i)
|
go func(j int) {
|
||||||
|
f(j)
|
||||||
|
wg.Done()
|
||||||
|
}(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
@ -97,7 +97,9 @@ func makeSwitch(cfg *cfg.P2PConfig, i int, network, version string, initSwitch f
|
|||||||
nodeKey := &NodeKey{
|
nodeKey := &NodeKey{
|
||||||
PrivKey: crypto.GenPrivKeyEd25519().Wrap(),
|
PrivKey: crypto.GenPrivKeyEd25519().Wrap(),
|
||||||
}
|
}
|
||||||
s := initSwitch(i, NewSwitch(cfg))
|
s := NewSwitch(cfg)
|
||||||
|
s.SetLogger(log.TestingLogger())
|
||||||
|
s = initSwitch(i, s)
|
||||||
s.SetNodeInfo(NodeInfo{
|
s.SetNodeInfo(NodeInfo{
|
||||||
PubKey: nodeKey.PubKey(),
|
PubKey: nodeKey.PubKey(),
|
||||||
Moniker: cmn.Fmt("switch%d", i),
|
Moniker: cmn.Fmt("switch%d", i),
|
||||||
@ -106,6 +108,5 @@ func makeSwitch(cfg *cfg.P2PConfig, i int, network, version string, initSwitch f
|
|||||||
ListenAddr: cmn.Fmt("%v:%v", network, rand.Intn(64512)+1023),
|
ListenAddr: cmn.Fmt("%v:%v", network, rand.Intn(64512)+1023),
|
||||||
})
|
})
|
||||||
s.SetNodeKey(nodeKey)
|
s.SetNodeKey(nodeKey)
|
||||||
s.SetLogger(log.TestingLogger())
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user