test: randConsensusNet takes more args
This commit is contained in:
parent
bcd8712ec3
commit
de6bba4609
|
@ -30,7 +30,7 @@ func init() {
|
||||||
// Heal partition and ensure A sees the commit
|
// Heal partition and ensure A sees the commit
|
||||||
func TestByzantine(t *testing.T) {
|
func TestByzantine(t *testing.T) {
|
||||||
N := 4
|
N := 4
|
||||||
css := randConsensusNet(N)
|
css := randConsensusNet(N, "consensus_byzantine_test", crankTimeoutPropose)
|
||||||
|
|
||||||
switches := make([]*p2p.Switch, N)
|
switches := make([]*p2p.Switch, N)
|
||||||
for i := 0; i < N; i++ {
|
for i := 0; i < N; i++ {
|
||||||
|
|
|
@ -257,15 +257,15 @@ func randConsensusState(nValidators int) (*ConsensusState, []*validatorStub) {
|
||||||
return cs, vss
|
return cs, vss
|
||||||
}
|
}
|
||||||
|
|
||||||
func randConsensusNet(nValidators int) []*ConsensusState {
|
func randConsensusNet(nValidators int, testName string, updateConfig func(cfg.Config)) []*ConsensusState {
|
||||||
genDoc, privVals := randGenesisDoc(nValidators, false, 10)
|
genDoc, privVals := randGenesisDoc(nValidators, false, 10)
|
||||||
css := make([]*ConsensusState, nValidators)
|
css := make([]*ConsensusState, nValidators)
|
||||||
for i := 0; i < nValidators; i++ {
|
for i := 0; i < nValidators; i++ {
|
||||||
db := dbm.NewMemDB() // each state needs its own db
|
db := dbm.NewMemDB() // each state needs its own db
|
||||||
state := sm.MakeGenesisState(db, genDoc)
|
state := sm.MakeGenesisState(db, genDoc)
|
||||||
state.Save()
|
state.Save()
|
||||||
thisConfig := tendermint_test.ResetConfig(Fmt("consensus_reactor_test_%d", i))
|
thisConfig := tendermint_test.ResetConfig(Fmt("%s_%d", testName, i))
|
||||||
resetConfigTimeouts(thisConfig)
|
updateConfig(thisConfig)
|
||||||
EnsureDir(thisConfig.GetString("cs_wal_dir"), 0700) // dir for wal
|
EnsureDir(thisConfig.GetString("cs_wal_dir"), 0700) // dir for wal
|
||||||
css[i] = newConsensusStateWithConfig(thisConfig, state, privVals[i], counter.NewCounterApplication(true))
|
css[i] = newConsensusStateWithConfig(thisConfig, state, privVals[i], counter.NewCounterApplication(true))
|
||||||
}
|
}
|
||||||
|
@ -273,15 +273,15 @@ func randConsensusNet(nValidators int) []*ConsensusState {
|
||||||
}
|
}
|
||||||
|
|
||||||
// nPeers = nValidators + nNotValidator
|
// nPeers = nValidators + nNotValidator
|
||||||
func randConsensusNetWithPeers(nValidators int, nPeers int) []*ConsensusState {
|
func randConsensusNetWithPeers(nValidators, nPeers int, testName string, updateConfig func(cfg.Config)) []*ConsensusState {
|
||||||
genDoc, privVals := randGenesisDoc(nValidators, false, int64(testMinPower))
|
genDoc, privVals := randGenesisDoc(nValidators, false, int64(testMinPower))
|
||||||
css := make([]*ConsensusState, nPeers)
|
css := make([]*ConsensusState, nPeers)
|
||||||
for i := 0; i < nPeers; i++ {
|
for i := 0; i < nPeers; i++ {
|
||||||
db := dbm.NewMemDB() // each state needs its own db
|
db := dbm.NewMemDB() // each state needs its own db
|
||||||
state := sm.MakeGenesisState(db, genDoc)
|
state := sm.MakeGenesisState(db, genDoc)
|
||||||
state.Save()
|
state.Save()
|
||||||
thisConfig := tendermint_test.ResetConfig(Fmt("consensus_reactor_test_%d", i))
|
thisConfig := tendermint_test.ResetConfig(Fmt("%s_%d", testName, i))
|
||||||
resetConfigTimeouts(thisConfig)
|
updateConfig(thisConfig)
|
||||||
EnsureDir(thisConfig.GetString("cs_wal_dir"), 0700) // dir for wal
|
EnsureDir(thisConfig.GetString("cs_wal_dir"), 0700) // dir for wal
|
||||||
var privVal *types.PrivValidator
|
var privVal *types.PrivValidator
|
||||||
if i < nValidators {
|
if i < nValidators {
|
||||||
|
@ -374,14 +374,8 @@ func getSwitchIndex(switches []*p2p.Switch, peer *p2p.Peer) int {
|
||||||
// so we dont violate synchrony assumptions
|
// so we dont violate synchrony assumptions
|
||||||
// TODO: make tests more robust to this instead (handle round changes)
|
// TODO: make tests more robust to this instead (handle round changes)
|
||||||
// XXX: especially a problem when running the race detector on circle
|
// XXX: especially a problem when running the race detector on circle
|
||||||
func resetConfigTimeouts(config cfg.Config) {
|
func crankTimeoutPropose(config cfg.Config) {
|
||||||
logger.SetLogLevel("info")
|
logger.SetLogLevel("info")
|
||||||
//config.Set("log_level", "notice")
|
|
||||||
config.Set("timeout_propose", 110000) // TODO: crank it to eleventy
|
config.Set("timeout_propose", 110000) // TODO: crank it to eleventy
|
||||||
// config.Set("timeout_propose_delta", 500)
|
|
||||||
// config.Set("timeout_prevote", 1000)
|
|
||||||
// config.Set("timeout_prevote_delta", 500)
|
|
||||||
// config.Set("timeout_precommit", 1000)
|
|
||||||
// config.Set("timeout_precommit_delta", 500)
|
|
||||||
config.Set("timeout_commit", 1000)
|
config.Set("timeout_commit", 1000)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ func init() {
|
||||||
// Ensure a testnet makes blocks
|
// Ensure a testnet makes blocks
|
||||||
func TestReactor(t *testing.T) {
|
func TestReactor(t *testing.T) {
|
||||||
N := 4
|
N := 4
|
||||||
css := randConsensusNet(N)
|
css := randConsensusNet(N, "consensus_reactor_test", crankTimeoutPropose)
|
||||||
reactors := make([]*ConsensusReactor, N)
|
reactors := make([]*ConsensusReactor, N)
|
||||||
eventChans := make([]chan interface{}, N)
|
eventChans := make([]chan interface{}, N)
|
||||||
for i := 0; i < N; i++ {
|
for i := 0; i < N; i++ {
|
||||||
|
@ -58,7 +58,7 @@ func TestReactor(t *testing.T) {
|
||||||
func TestValidatorSetChanges(t *testing.T) {
|
func TestValidatorSetChanges(t *testing.T) {
|
||||||
nPeers := 8
|
nPeers := 8
|
||||||
nVals := 4
|
nVals := 4
|
||||||
css := randConsensusNetWithPeers(nVals, nPeers)
|
css := randConsensusNetWithPeers(nVals, nPeers, "consensus_val_set_changes_test", crankTimeoutPropose)
|
||||||
reactors := make([]*ConsensusReactor, nPeers)
|
reactors := make([]*ConsensusReactor, nPeers)
|
||||||
eventChans := make([]chan interface{}, nPeers)
|
eventChans := make([]chan interface{}, nPeers)
|
||||||
for i := 0; i < nPeers; i++ {
|
for i := 0; i < nPeers; i++ {
|
||||||
|
@ -119,8 +119,10 @@ func TestValidatorSetChanges(t *testing.T) {
|
||||||
|
|
||||||
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(wg *sync.WaitGroup, j int) {
|
||||||
newBlock := <-eventChans[j]
|
newBlockI := <-eventChans[j]
|
||||||
err := validateBlock(newBlock.(types.EventDataNewBlock).Block, activeVals)
|
newBlock := newBlockI.(types.EventDataNewBlock).Block
|
||||||
|
log.Info("Got block", "height", newBlock.Height, "validator", j)
|
||||||
|
err := validateBlock(newBlock, activeVals)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,7 +270,7 @@ func (commit *Commit) BitArray() *BitArray {
|
||||||
commit.bitArray.SetIndex(i, precommit != nil)
|
commit.bitArray.SetIndex(i, precommit != nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return commit.bitArray.Copy()
|
return commit.bitArray
|
||||||
}
|
}
|
||||||
|
|
||||||
func (commit *Commit) GetByIndex(index int) *Vote {
|
func (commit *Commit) GetByIndex(index int) *Vote {
|
||||||
|
|
Loading…
Reference in New Issue