diff --git a/consensus/common_test.go b/consensus/common_test.go index 8197d6d6..bf805e09 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -31,7 +31,7 @@ import ( // genesis, chain_id, priv_val var config *cfg.Config // NOTE: must be reset for each _test.go file -var ensureTimeout = time.Duration(2) +var ensureTimeout = time.Second * 2 func ensureDir(dir string, mode os.FileMode) { if err := EnsureDir(dir, mode); err != nil { @@ -297,7 +297,7 @@ func randConsensusState(nValidators int) (*ConsensusState, []*validatorStub) { //------------------------------------------------------------------------------- func ensureNoNewStep(stepCh chan interface{}) { - timer := time.NewTimer(ensureTimeout * time.Second) + timer := time.NewTimer(ensureTimeout) select { case <-timer.C: break @@ -307,7 +307,7 @@ func ensureNoNewStep(stepCh chan interface{}) { } func ensureNewStep(stepCh chan interface{}) { - timer := time.NewTimer(ensureTimeout * time.Second) + timer := time.NewTimer(ensureTimeout) select { case <-timer.C: panic("We shouldnt be stuck waiting") diff --git a/consensus/mempool_test.go b/consensus/mempool_test.go index e4069b87..0f726b39 100644 --- a/consensus/mempool_test.go +++ b/consensus/mempool_test.go @@ -34,6 +34,21 @@ func TestNoProgressUntilTxsAvailable(t *testing.T) { } +func TestProgressAfterCreateEmptyBlocksInterval(t *testing.T) { + config := ResetConfig("consensus_mempool_txs_available_test") + config.Consensus.CreateEmptyBlocksInterval = int(ensureTimeout.Seconds()) + state, privVals := randGenesisState(1, false, 10) + cs := newConsensusStateWithConfig(config, state, privVals[0], NewCounterApplication()) + cs.mempool.EnableTxsAvailable() + height, round := cs.Height, cs.Round + newBlockCh := subscribeToEvent(cs.evsw, "tester", types.EventStringNewBlock(), 1) + startTestRound(cs, height, round) + + ensureNewStep(newBlockCh) // first block gets committed + ensureNoNewStep(newBlockCh) // then we dont make a block ... + ensureNewStep(newBlockCh) // until the CreateEmptyBlocksInterval has passed +} + func TestProgressInHigherRound(t *testing.T) { config := ResetConfig("consensus_mempool_txs_available_test") config.Consensus.CreateEmptyBlocks = false