Browse Source

consensus: t.Fatal -> panic

pull/233/head
Ethan Buchman 8 years ago
parent
commit
47acada2cb
6 changed files with 42 additions and 37 deletions
  1. +4
    -4
      consensus/common_test.go
  2. +4
    -3
      consensus/height_vote_set_test.go
  3. +2
    -2
      consensus/mempool_test.go
  4. +6
    -5
      consensus/replay_test.go
  5. +17
    -16
      consensus/state_test.go
  6. +9
    -7
      consensus/wal_test.go

+ 4
- 4
consensus/common_test.go View File

@ -99,18 +99,18 @@ func changeProposer(t *testing.T, perspectiveOf *ConsensusState, newProposer *va
_, v1 := perspectiveOf.Validators.GetByAddress(perspectiveOf.privValidator.Address)
v1.Accum, v1.VotingPower = 0, 0
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.Accum, v2.VotingPower = 100, 100
if updated := perspectiveOf.Validators.Update(v2); !updated {
t.Fatal("failed to update validator")
panic("failed to update validator")
}
// make the proposal
propBlock, _ := perspectiveOf.createProposalBlock()
if propBlock == nil {
t.Fatal("Failed to create proposal block with cs2")
panic("Failed to create proposal block with cs2")
}
return propBlock
}
@ -120,7 +120,7 @@ func fixVotingPower(t *testing.T, cs1 *ConsensusState, addr2 []byte) {
_, v2 := cs1.Validators.GetByAddress(addr2)
v1.Accum, v1.VotingPower = v2.Accum, v2.VotingPower
if updated := cs1.Validators.Update(v1); !updated {
t.Fatal("failed to update validator")
panic("failed to update validator")
}
}


+ 4
- 3
consensus/height_vote_set_test.go View File

@ -1,10 +1,11 @@
package consensus
import (
"testing"
. "github.com/tendermint/go-common"
"github.com/tendermint/tendermint/config/tendermint_test"
"github.com/tendermint/tendermint/types"
"testing"
)
func init() {
@ -45,7 +46,7 @@ func makeVoteHR(t *testing.T, height, round int, privVal *types.PrivValidator) *
chainID := config.GetString("chain_id")
err := privVal.SignVote(chainID, vote)
if err != nil {
t.Fatalf("Error signing vote: %v", err)
panic(Fmt("Error signing vote: %v", err))
return nil
}
return vote


+ 2
- 2
consensus/mempool_test.go View File

@ -31,7 +31,7 @@ func TestTxConcurrentWithCommit(t *testing.T) {
binary.BigEndian.PutUint64(txBytes, uint64(i))
err := cs.mempool.CheckTx(txBytes, 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)))
}
@ -47,7 +47,7 @@ func TestTxConcurrentWithCommit(t *testing.T) {
case b := <-newBlockCh:
nTxs += b.(types.EventDataNewBlock).Block.Header.NumTxs
case <-ticker.C:
t.Fatal("Timed out waiting to commit blocks with transactions")
panic("Timed out waiting to commit blocks with transactions")
}
}
}


+ 6
- 5
consensus/replay_test.go View File

@ -6,6 +6,7 @@ import (
"testing"
"time"
. "github.com/tendermint/go-common"
"github.com/tendermint/tendermint/types"
)
@ -59,12 +60,12 @@ func TestReplayCatchup(t *testing.T) {
// write the needed wal to file
f, err := ioutil.TempFile(os.TempDir(), "replay_test_")
if err != nil {
t.Fatal(err)
panic(err)
}
name := f.Name()
_, err = f.WriteString(testLog)
if err != nil {
t.Fatal(err)
panic(err)
}
f.Close()
@ -83,14 +84,14 @@ func TestReplayCatchup(t *testing.T) {
// open wal and run catchup messages
openWAL(t, cs, name)
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)
select {
case <-newBlockCh:
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
wal, err := NewWAL(file, config.GetBool("cswal_light"))
if err != nil {
t.Fatal(err)
panic(err)
}
wal.exists = true
cs.wal = wal


+ 17
- 16
consensus/state_test.go View File

@ -8,6 +8,7 @@ import (
"github.com/tendermint/tendermint/config/tendermint_test"
//"github.com/tendermint/go-events"
. "github.com/tendermint/go-common"
"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
prop := cs1.GetRoundState().Validators.Proposer()
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
@ -81,7 +82,7 @@ func TestProposerSelection0(t *testing.T) {
prop = cs1.GetRoundState().Validators.Proposer()
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++ {
prop := cs1.GetRoundState().Validators.Proposer()
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()
@ -130,7 +131,7 @@ func TestEnterProposeNoPrivValidator(t *testing.T) {
select {
case <-timeoutCh:
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())
select {
case <-timeoutCh:
t.Fatal("Expected EnterPropose not to timeout")
panic("Expected EnterPropose not to timeout")
case <-ticker.C:
}
@ -200,7 +201,7 @@ func TestBadProposal(t *testing.T) {
propBlockParts := propBlock.MakePartSet()
proposal := types.NewProposal(cs2.Height, round, propBlockParts.Header(), -1)
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
@ -377,7 +378,7 @@ func TestLockNoPOL(t *testing.T) {
rs = re.(types.EventDataRoundState).RoundState.(*RoundState)
if rs.ProposalBlock != nil {
t.Fatal("Expected proposal block to be nil")
panic("Expected proposal block to be nil")
}
// wait to finish prevote
@ -420,7 +421,7 @@ func TestLockNoPOL(t *testing.T) {
// now we're on a new round and are the proposer
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
@ -440,7 +441,7 @@ func TestLockNoPOL(t *testing.T) {
// before we time out into new round, set next proposal block
prop, propBlock := decideProposal(cs1, cs2, cs2.Height, cs2.Round+1)
if prop == nil || propBlock == nil {
t.Fatal("Failed to create proposal block with cs2")
panic("Failed to create proposal block with cs2")
}
incrementRound(cs2)
@ -567,11 +568,11 @@ func TestLockPOLRelock(t *testing.T) {
re = <-newRoundCh
rs = re.(types.EventDataRoundState).RoundState.(*RoundState)
if rs.Height != 2 {
t.Fatal("Expected height to increment")
panic("Expected height to increment")
}
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.VotingPower = 1
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()))
@ -734,7 +735,7 @@ func TestLockPOLSafety1(t *testing.T) {
rs = re.(types.EventDataRoundState).RoundState.(*RoundState)
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))
// 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
newProp := types.NewProposal(height, 2, propBlockParts0.Header(), 0)
if err := cs3.SignProposal(config.GetString("chain_id"), newProp); err != nil {
t.Fatal(err)
panic(err)
}
cs1.SetProposalAndBlock(newProp, propBlock0, propBlockParts0, "some peer")
addVoteToFromMany(cs1, prevotes, cs2, cs3, cs4) // add the pol votes
@ -865,7 +866,7 @@ func TestLockPOLSafety2(t *testing.T) {
select {
case <-unlockCh:
t.Fatal("validator unlocked using an old polka")
panic("validator unlocked using an old polka")
case <-voteCh:
// prevote our locked block
}
@ -1016,6 +1017,6 @@ func TestHalt1(t *testing.T) {
rs = re.(types.EventDataRoundState).RoundState.(*RoundState)
if rs.Height != 2 {
t.Fatal("expected height to increment")
panic("expected height to increment")
}
}

+ 9
- 7
consensus/wal_test.go View File

@ -6,6 +6,8 @@ import (
"path"
"strings"
"testing"
. "github.com/tendermint/go-common"
)
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) {
f, err := ioutil.TempFile(os.TempDir(), "seek_test_")
if err != nil {
t.Fatal(err)
panic(err)
}
stat, _ := f.Stat()
@ -26,13 +28,13 @@ func TestSeek(t *testing.T) {
_, err = f.WriteString(testTxt)
if err != nil {
t.Fatal(err)
panic(err)
}
f.Close()
wal, err := NewWAL(path.Join(os.TempDir(), name), config.GetBool("cswal_light"))
if err != nil {
t.Fatal(err)
panic(err)
}
keyWord := "Precommit"
@ -43,7 +45,7 @@ func TestSeek(t *testing.T) {
return false
})
if err != nil {
t.Fatal(err)
panic(err)
}
// confirm n
@ -58,18 +60,18 @@ func TestSeek(t *testing.T) {
// n is lines from the end.
spl = spl[i:]
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)
if err != nil {
t.Fatal(err)
panic(err)
}
// first char is a \n
spl2 := strings.Split(strings.Trim(string(b), "\n"), "\n")
for i, s := range spl {
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…
Cancel
Save