mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
consensus: t.Fatal -> panic
This commit is contained in:
parent
dd788c5631
commit
47acada2cb
@ -99,18 +99,18 @@ func changeProposer(t *testing.T, perspectiveOf *ConsensusState, newProposer *va
|
|||||||
_, v1 := perspectiveOf.Validators.GetByAddress(perspectiveOf.privValidator.Address)
|
_, v1 := perspectiveOf.Validators.GetByAddress(perspectiveOf.privValidator.Address)
|
||||||
v1.Accum, v1.VotingPower = 0, 0
|
v1.Accum, v1.VotingPower = 0, 0
|
||||||
if updated := perspectiveOf.Validators.Update(v1); !updated {
|
if updated := perspectiveOf.Validators.Update(v1); !updated {
|
||||||
t.Fatal("failed to update validator")
|
panic("failed to update validator")
|
||||||
}
|
}
|
||||||
_, v2 := perspectiveOf.Validators.GetByAddress(newProposer.Address)
|
_, v2 := perspectiveOf.Validators.GetByAddress(newProposer.Address)
|
||||||
v2.Accum, v2.VotingPower = 100, 100
|
v2.Accum, v2.VotingPower = 100, 100
|
||||||
if updated := perspectiveOf.Validators.Update(v2); !updated {
|
if updated := perspectiveOf.Validators.Update(v2); !updated {
|
||||||
t.Fatal("failed to update validator")
|
panic("failed to update validator")
|
||||||
}
|
}
|
||||||
|
|
||||||
// make the proposal
|
// make the proposal
|
||||||
propBlock, _ := perspectiveOf.createProposalBlock()
|
propBlock, _ := perspectiveOf.createProposalBlock()
|
||||||
if propBlock == nil {
|
if propBlock == nil {
|
||||||
t.Fatal("Failed to create proposal block with cs2")
|
panic("Failed to create proposal block with cs2")
|
||||||
}
|
}
|
||||||
return propBlock
|
return propBlock
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ func fixVotingPower(t *testing.T, cs1 *ConsensusState, addr2 []byte) {
|
|||||||
_, v2 := cs1.Validators.GetByAddress(addr2)
|
_, v2 := cs1.Validators.GetByAddress(addr2)
|
||||||
v1.Accum, v1.VotingPower = v2.Accum, v2.VotingPower
|
v1.Accum, v1.VotingPower = v2.Accum, v2.VotingPower
|
||||||
if updated := cs1.Validators.Update(v1); !updated {
|
if updated := cs1.Validators.Update(v1); !updated {
|
||||||
t.Fatal("failed to update validator")
|
panic("failed to update validator")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package consensus
|
package consensus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/tendermint/go-common"
|
||||||
"github.com/tendermint/tendermint/config/tendermint_test"
|
"github.com/tendermint/tendermint/config/tendermint_test"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -45,7 +46,7 @@ func makeVoteHR(t *testing.T, height, round int, privVal *types.PrivValidator) *
|
|||||||
chainID := config.GetString("chain_id")
|
chainID := config.GetString("chain_id")
|
||||||
err := privVal.SignVote(chainID, vote)
|
err := privVal.SignVote(chainID, vote)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error signing vote: %v", err)
|
panic(Fmt("Error signing vote: %v", err))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return vote
|
return vote
|
||||||
|
@ -31,7 +31,7 @@ func TestTxConcurrentWithCommit(t *testing.T) {
|
|||||||
binary.BigEndian.PutUint64(txBytes, uint64(i))
|
binary.BigEndian.PutUint64(txBytes, uint64(i))
|
||||||
err := cs.mempool.CheckTx(txBytes, nil)
|
err := cs.mempool.CheckTx(txBytes, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Error after CheckTx: %v", err)
|
panic(Fmt("Error after CheckTx: %v", err))
|
||||||
}
|
}
|
||||||
// time.Sleep(time.Microsecond * time.Duration(rand.Int63n(3000)))
|
// time.Sleep(time.Microsecond * time.Duration(rand.Int63n(3000)))
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ func TestTxConcurrentWithCommit(t *testing.T) {
|
|||||||
case b := <-newBlockCh:
|
case b := <-newBlockCh:
|
||||||
nTxs += b.(types.EventDataNewBlock).Block.Header.NumTxs
|
nTxs += b.(types.EventDataNewBlock).Block.Header.NumTxs
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
t.Fatal("Timed out waiting to commit blocks with transactions")
|
panic("Timed out waiting to commit blocks with transactions")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
. "github.com/tendermint/go-common"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -59,12 +60,12 @@ func TestReplayCatchup(t *testing.T) {
|
|||||||
// write the needed wal to file
|
// write the needed wal to file
|
||||||
f, err := ioutil.TempFile(os.TempDir(), "replay_test_")
|
f, err := ioutil.TempFile(os.TempDir(), "replay_test_")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
name := f.Name()
|
name := f.Name()
|
||||||
_, err = f.WriteString(testLog)
|
_, err = f.WriteString(testLog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
@ -83,14 +84,14 @@ func TestReplayCatchup(t *testing.T) {
|
|||||||
// open wal and run catchup messages
|
// open wal and run catchup messages
|
||||||
openWAL(t, cs, name)
|
openWAL(t, cs, name)
|
||||||
if err := cs.catchupReplay(cs.Height); err != nil {
|
if err := cs.catchupReplay(cs.Height); err != nil {
|
||||||
t.Fatalf("Error on catchup replay %v", err)
|
panic(Fmt("Error on catchup replay %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
after := time.After(time.Second * 15)
|
after := time.After(time.Second * 15)
|
||||||
select {
|
select {
|
||||||
case <-newBlockCh:
|
case <-newBlockCh:
|
||||||
case <-after:
|
case <-after:
|
||||||
t.Fatal("Timed out waiting for new block")
|
panic("Timed out waiting for new block")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +99,7 @@ func openWAL(t *testing.T, cs *ConsensusState, file string) {
|
|||||||
// open the wal
|
// open the wal
|
||||||
wal, err := NewWAL(file, config.GetBool("cswal_light"))
|
wal, err := NewWAL(file, config.GetBool("cswal_light"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
wal.exists = true
|
wal.exists = true
|
||||||
cs.wal = wal
|
cs.wal = wal
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/tendermint/tendermint/config/tendermint_test"
|
"github.com/tendermint/tendermint/config/tendermint_test"
|
||||||
//"github.com/tendermint/go-events"
|
//"github.com/tendermint/go-events"
|
||||||
|
. "github.com/tendermint/go-common"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ func TestProposerSelection0(t *testing.T) {
|
|||||||
// lets commit a block and ensure proposer for the next height is correct
|
// lets commit a block and ensure proposer for the next height is correct
|
||||||
prop := cs1.GetRoundState().Validators.Proposer()
|
prop := cs1.GetRoundState().Validators.Proposer()
|
||||||
if !bytes.Equal(prop.Address, cs1.privValidator.Address) {
|
if !bytes.Equal(prop.Address, cs1.privValidator.Address) {
|
||||||
t.Fatalf("expected proposer to be validator %d. Got %X", 0, prop.Address)
|
panic(Fmt("expected proposer to be validator %d. Got %X", 0, prop.Address))
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for complete proposal
|
// wait for complete proposal
|
||||||
@ -81,7 +82,7 @@ func TestProposerSelection0(t *testing.T) {
|
|||||||
|
|
||||||
prop = cs1.GetRoundState().Validators.Proposer()
|
prop = cs1.GetRoundState().Validators.Proposer()
|
||||||
if !bytes.Equal(prop.Address, vss[1].Address) {
|
if !bytes.Equal(prop.Address, vss[1].Address) {
|
||||||
t.Fatalf("expected proposer to be validator %d. Got %X", 1, prop.Address)
|
panic(Fmt("expected proposer to be validator %d. Got %X", 1, prop.Address))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ func TestProposerSelection2(t *testing.T) {
|
|||||||
for i := 0; i < len(vss); i++ {
|
for i := 0; i < len(vss); i++ {
|
||||||
prop := cs1.GetRoundState().Validators.Proposer()
|
prop := cs1.GetRoundState().Validators.Proposer()
|
||||||
if !bytes.Equal(prop.Address, vss[(i+2)%len(vss)].Address) {
|
if !bytes.Equal(prop.Address, vss[(i+2)%len(vss)].Address) {
|
||||||
t.Fatalf("expected proposer to be validator %d. Got %X", (i+2)%len(vss), prop.Address)
|
panic(Fmt("expected proposer to be validator %d. Got %X", (i+2)%len(vss), prop.Address))
|
||||||
}
|
}
|
||||||
|
|
||||||
rs := cs1.GetRoundState()
|
rs := cs1.GetRoundState()
|
||||||
@ -130,7 +131,7 @@ func TestEnterProposeNoPrivValidator(t *testing.T) {
|
|||||||
select {
|
select {
|
||||||
case <-timeoutCh:
|
case <-timeoutCh:
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
t.Fatal("Expected EnterPropose to timeout")
|
panic("Expected EnterPropose to timeout")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +171,7 @@ func TestEnterProposeYesPrivValidator(t *testing.T) {
|
|||||||
ticker := time.NewTicker(cs.timeoutParams.ensureProposeTimeout())
|
ticker := time.NewTicker(cs.timeoutParams.ensureProposeTimeout())
|
||||||
select {
|
select {
|
||||||
case <-timeoutCh:
|
case <-timeoutCh:
|
||||||
t.Fatal("Expected EnterPropose not to timeout")
|
panic("Expected EnterPropose not to timeout")
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -200,7 +201,7 @@ func TestBadProposal(t *testing.T) {
|
|||||||
propBlockParts := propBlock.MakePartSet()
|
propBlockParts := propBlock.MakePartSet()
|
||||||
proposal := types.NewProposal(cs2.Height, round, propBlockParts.Header(), -1)
|
proposal := types.NewProposal(cs2.Height, round, propBlockParts.Header(), -1)
|
||||||
if err := cs2.SignProposal(config.GetString("chain_id"), proposal); err != nil {
|
if err := cs2.SignProposal(config.GetString("chain_id"), proposal); err != nil {
|
||||||
t.Fatal("failed to sign bad proposal", err)
|
panic("failed to sign bad proposal: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the proposal block
|
// set the proposal block
|
||||||
@ -377,7 +378,7 @@ func TestLockNoPOL(t *testing.T) {
|
|||||||
rs = re.(types.EventDataRoundState).RoundState.(*RoundState)
|
rs = re.(types.EventDataRoundState).RoundState.(*RoundState)
|
||||||
|
|
||||||
if rs.ProposalBlock != nil {
|
if rs.ProposalBlock != nil {
|
||||||
t.Fatal("Expected proposal block to be nil")
|
panic("Expected proposal block to be nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait to finish prevote
|
// wait to finish prevote
|
||||||
@ -420,7 +421,7 @@ func TestLockNoPOL(t *testing.T) {
|
|||||||
|
|
||||||
// now we're on a new round and are the proposer
|
// now we're on a new round and are the proposer
|
||||||
if !bytes.Equal(rs.ProposalBlock.Hash(), rs.LockedBlock.Hash()) {
|
if !bytes.Equal(rs.ProposalBlock.Hash(), rs.LockedBlock.Hash()) {
|
||||||
t.Fatalf("Expected proposal block to be locked block. Got %v, Expected %v", rs.ProposalBlock, rs.LockedBlock)
|
panic(Fmt("Expected proposal block to be locked block. Got %v, Expected %v", rs.ProposalBlock, rs.LockedBlock))
|
||||||
}
|
}
|
||||||
|
|
||||||
<-voteCh // prevote
|
<-voteCh // prevote
|
||||||
@ -440,7 +441,7 @@ func TestLockNoPOL(t *testing.T) {
|
|||||||
// before we time out into new round, set next proposal block
|
// before we time out into new round, set next proposal block
|
||||||
prop, propBlock := decideProposal(cs1, cs2, cs2.Height, cs2.Round+1)
|
prop, propBlock := decideProposal(cs1, cs2, cs2.Height, cs2.Round+1)
|
||||||
if prop == nil || propBlock == nil {
|
if prop == nil || propBlock == nil {
|
||||||
t.Fatal("Failed to create proposal block with cs2")
|
panic("Failed to create proposal block with cs2")
|
||||||
}
|
}
|
||||||
|
|
||||||
incrementRound(cs2)
|
incrementRound(cs2)
|
||||||
@ -567,11 +568,11 @@ func TestLockPOLRelock(t *testing.T) {
|
|||||||
re = <-newRoundCh
|
re = <-newRoundCh
|
||||||
rs = re.(types.EventDataRoundState).RoundState.(*RoundState)
|
rs = re.(types.EventDataRoundState).RoundState.(*RoundState)
|
||||||
if rs.Height != 2 {
|
if rs.Height != 2 {
|
||||||
t.Fatal("Expected height to increment")
|
panic("Expected height to increment")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(b.Header.Hash(), propBlockHash) {
|
if !bytes.Equal(b.Header.Hash(), propBlockHash) {
|
||||||
t.Fatal("Expected new block to be proposal block")
|
panic("Expected new block to be proposal block")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -699,7 +700,7 @@ func TestLockPOLSafety1(t *testing.T) {
|
|||||||
_, v1 := cs1.Validators.GetByAddress(vss[0].Address)
|
_, v1 := cs1.Validators.GetByAddress(vss[0].Address)
|
||||||
v1.VotingPower = 1
|
v1.VotingPower = 1
|
||||||
if updated := cs1.Validators.Update(v1); !updated {
|
if updated := cs1.Validators.Update(v1); !updated {
|
||||||
t.Fatal("failed to update validator")
|
panic("failed to update validator")
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
log.Warn("old prop", "hash", fmt.Sprintf("%X", propBlock.Hash()))
|
log.Warn("old prop", "hash", fmt.Sprintf("%X", propBlock.Hash()))
|
||||||
@ -734,7 +735,7 @@ func TestLockPOLSafety1(t *testing.T) {
|
|||||||
rs = re.(types.EventDataRoundState).RoundState.(*RoundState)
|
rs = re.(types.EventDataRoundState).RoundState.(*RoundState)
|
||||||
|
|
||||||
if rs.LockedBlock != nil {
|
if rs.LockedBlock != nil {
|
||||||
t.Fatal("we should not be locked!")
|
panic("we should not be locked!")
|
||||||
}
|
}
|
||||||
log.Warn("new prop", "hash", fmt.Sprintf("%X", propBlockHash))
|
log.Warn("new prop", "hash", fmt.Sprintf("%X", propBlockHash))
|
||||||
// go to prevote, prevote for proposal block
|
// go to prevote, prevote for proposal block
|
||||||
@ -846,7 +847,7 @@ func TestLockPOLSafety2(t *testing.T) {
|
|||||||
// in round 2 we see the polkad block from round 0
|
// in round 2 we see the polkad block from round 0
|
||||||
newProp := types.NewProposal(height, 2, propBlockParts0.Header(), 0)
|
newProp := types.NewProposal(height, 2, propBlockParts0.Header(), 0)
|
||||||
if err := cs3.SignProposal(config.GetString("chain_id"), newProp); err != nil {
|
if err := cs3.SignProposal(config.GetString("chain_id"), newProp); err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
cs1.SetProposalAndBlock(newProp, propBlock0, propBlockParts0, "some peer")
|
cs1.SetProposalAndBlock(newProp, propBlock0, propBlockParts0, "some peer")
|
||||||
addVoteToFromMany(cs1, prevotes, cs2, cs3, cs4) // add the pol votes
|
addVoteToFromMany(cs1, prevotes, cs2, cs3, cs4) // add the pol votes
|
||||||
@ -865,7 +866,7 @@ func TestLockPOLSafety2(t *testing.T) {
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case <-unlockCh:
|
case <-unlockCh:
|
||||||
t.Fatal("validator unlocked using an old polka")
|
panic("validator unlocked using an old polka")
|
||||||
case <-voteCh:
|
case <-voteCh:
|
||||||
// prevote our locked block
|
// prevote our locked block
|
||||||
}
|
}
|
||||||
@ -1016,6 +1017,6 @@ func TestHalt1(t *testing.T) {
|
|||||||
rs = re.(types.EventDataRoundState).RoundState.(*RoundState)
|
rs = re.(types.EventDataRoundState).RoundState.(*RoundState)
|
||||||
|
|
||||||
if rs.Height != 2 {
|
if rs.Height != 2 {
|
||||||
t.Fatal("expected height to increment")
|
panic("expected height to increment")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/tendermint/go-common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testTxt = `{"time":"2016-01-16T04:42:00.390Z","msg":[1,{"height":28219,"round":0,"step":"RoundStepPrevote"}]}
|
var testTxt = `{"time":"2016-01-16T04:42:00.390Z","msg":[1,{"height":28219,"round":0,"step":"RoundStepPrevote"}]}
|
||||||
@ -18,7 +20,7 @@ var testTxt = `{"time":"2016-01-16T04:42:00.390Z","msg":[1,{"height":28219,"roun
|
|||||||
func TestSeek(t *testing.T) {
|
func TestSeek(t *testing.T) {
|
||||||
f, err := ioutil.TempFile(os.TempDir(), "seek_test_")
|
f, err := ioutil.TempFile(os.TempDir(), "seek_test_")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
stat, _ := f.Stat()
|
stat, _ := f.Stat()
|
||||||
@ -26,13 +28,13 @@ func TestSeek(t *testing.T) {
|
|||||||
|
|
||||||
_, err = f.WriteString(testTxt)
|
_, err = f.WriteString(testTxt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
wal, err := NewWAL(path.Join(os.TempDir(), name), config.GetBool("cswal_light"))
|
wal, err := NewWAL(path.Join(os.TempDir(), name), config.GetBool("cswal_light"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
keyWord := "Precommit"
|
keyWord := "Precommit"
|
||||||
@ -43,7 +45,7 @@ func TestSeek(t *testing.T) {
|
|||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// confirm n
|
// confirm n
|
||||||
@ -58,18 +60,18 @@ func TestSeek(t *testing.T) {
|
|||||||
// n is lines from the end.
|
// n is lines from the end.
|
||||||
spl = spl[i:]
|
spl = spl[i:]
|
||||||
if n != len(spl) {
|
if n != len(spl) {
|
||||||
t.Fatalf("Wrong nLines. Got %d, expected %d", n, len(spl))
|
panic(Fmt("Wrong nLines. Got %d, expected %d", n, len(spl)))
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := ioutil.ReadAll(wal.fp)
|
b, err := ioutil.ReadAll(wal.fp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
// first char is a \n
|
// first char is a \n
|
||||||
spl2 := strings.Split(strings.Trim(string(b), "\n"), "\n")
|
spl2 := strings.Split(strings.Trim(string(b), "\n"), "\n")
|
||||||
for i, s := range spl {
|
for i, s := range spl {
|
||||||
if s != spl2[i] {
|
if s != spl2[i] {
|
||||||
t.Fatalf("Mismatch. Got %s, expected %s", spl2[i], s)
|
panic(Fmt("Mismatch. Got %s, expected %s", spl2[i], s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user