mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-24 22:32:15 +00:00
fixes after my own review
This commit is contained in:
parent
c6f025f40e
commit
5cb936fa00
@ -264,9 +264,12 @@ func (w *crashingWAL) Wait() { w.next.Wait() }
|
|||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
// Handshake Tests
|
// Handshake Tests
|
||||||
|
|
||||||
var (
|
const (
|
||||||
NUM_BLOCKS = 6
|
NUM_BLOCKS = 6
|
||||||
mempool = types.MockMempool{}
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
mempool = types.MockMempool{}
|
||||||
)
|
)
|
||||||
|
|
||||||
//---------------------------------------
|
//---------------------------------------
|
||||||
@ -305,12 +308,12 @@ func TestHandshakeReplayNone(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeWAL(walMsgs []byte) string {
|
func tempWALWithData(data []byte) string {
|
||||||
walFile, err := ioutil.TempFile("", "wal")
|
walFile, err := ioutil.TempFile("", "wal")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("failed to create temp WAL file: %v", err))
|
panic(fmt.Errorf("failed to create temp WAL file: %v", err))
|
||||||
}
|
}
|
||||||
_, err = walFile.Write(walMsgs)
|
_, err = walFile.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("failed to write to temp WAL file: %v", err))
|
panic(fmt.Errorf("failed to write to temp WAL file: %v", err))
|
||||||
}
|
}
|
||||||
@ -324,11 +327,11 @@ func writeWAL(walMsgs []byte) string {
|
|||||||
func testHandshakeReplay(t *testing.T, nBlocks int, mode uint) {
|
func testHandshakeReplay(t *testing.T, nBlocks int, mode uint) {
|
||||||
config := ResetConfig("proxy_test_")
|
config := ResetConfig("proxy_test_")
|
||||||
|
|
||||||
walBody, err := GenWAL(NUM_BLOCKS)
|
walBody, err := WALWithNBlocks(NUM_BLOCKS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
walFile := writeWAL(walBody)
|
walFile := tempWALWithData(walBody)
|
||||||
config.Consensus.SetWalFile(walFile)
|
config.Consensus.SetWalFile(walFile)
|
||||||
|
|
||||||
privVal := types.LoadPrivValidatorFS(config.PrivValidatorFile())
|
privVal := types.LoadPrivValidatorFS(config.PrivValidatorFile())
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
// walgen provides an utility function for generating WAL on the fly.
|
|
||||||
package consensus
|
package consensus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -23,15 +22,17 @@ import (
|
|||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GenWAL generates a consensus WAL. It does this by spining up a new node with a
|
// WALWithNBlocks generates a consensus WAL. It does this by spining up a
|
||||||
// dummy application and special consensus wal instance (byteBufferWAL) and
|
// stripped down version of node (proxy app, event bus, consensus state) with a
|
||||||
// waits until numBlocks are created. Then it returns a WAL body.
|
// persistent dummy application and special consensus wal instance
|
||||||
func GenWAL(numBlocks int) (body []byte, err error) {
|
// (byteBufferWAL) and waits until numBlocks are created. Then it returns a WAL
|
||||||
|
// content.
|
||||||
|
func WALWithNBlocks(numBlocks int) (data []byte, err error) {
|
||||||
config := getConfig()
|
config := getConfig()
|
||||||
|
|
||||||
app := dummy.NewPersistentDummyApplication(filepath.Join(config.DBDir(), "genwal"))
|
app := dummy.NewPersistentDummyApplication(filepath.Join(config.DBDir(), "wal_generator"))
|
||||||
|
|
||||||
logger := log.TestingLogger().With("walgen", "walgen")
|
logger := log.NewNopLogger() // log.TestingLogger().With("wal_generator", "wal_generator")
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// COPY PASTE FROM node.go WITH A FEW MODIFICATIONS
|
// COPY PASTE FROM node.go WITH A FEW MODIFICATIONS
|
||||||
@ -77,6 +78,7 @@ func GenWAL(numBlocks int) (body []byte, err error) {
|
|||||||
wr := bufio.NewWriter(&b)
|
wr := bufio.NewWriter(&b)
|
||||||
numBlocksWritten := make(chan struct{})
|
numBlocksWritten := make(chan struct{})
|
||||||
wal := &byteBufferWAL{enc: NewWALEncoder(wr), heightToStop: int64(numBlocks), signalWhenStopsTo: numBlocksWritten}
|
wal := &byteBufferWAL{enc: NewWALEncoder(wr), heightToStop: int64(numBlocks), signalWhenStopsTo: numBlocksWritten}
|
||||||
|
// see wal.go#103
|
||||||
wal.Save(EndHeightMessage{0})
|
wal.Save(EndHeightMessage{0})
|
||||||
consensusState.wal = wal
|
consensusState.wal = wal
|
||||||
|
|
||||||
@ -142,11 +144,12 @@ type byteBufferWAL struct {
|
|||||||
signalWhenStopsTo chan struct{}
|
signalWhenStopsTo chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var fixedTime, err = time.Parse(time.RFC3339, "2017-01-02T15:04:05Z")
|
// needed for determinism
|
||||||
|
var fixedTime, _ = time.Parse(time.RFC3339, "2017-01-02T15:04:05Z")
|
||||||
|
|
||||||
// Save writes message to the internal buffer except when heightToStop is
|
// Save writes message to the internal buffer except when heightToStop is
|
||||||
// reached, in which case it signal the caller via signalWhenStopsTo and skip
|
// reached, in which case it will signal the caller via signalWhenStopsTo and
|
||||||
// writing.
|
// skip writing.
|
||||||
func (w *byteBufferWAL) Save(m WALMessage) {
|
func (w *byteBufferWAL) Save(m WALMessage) {
|
||||||
if w.stopped {
|
if w.stopped {
|
||||||
return
|
return
|
@ -42,11 +42,11 @@ func TestWALEncoderDecoder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSearchForEndHeight(t *testing.T) {
|
func TestSearchForEndHeight(t *testing.T) {
|
||||||
walBody, err := GenWAL(6)
|
walBody, err := WALWithNBlocks(6)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
walFile := writeWAL(walBody)
|
walFile := tempWALWithData(walBody)
|
||||||
|
|
||||||
wal, err := NewWAL(walFile, false)
|
wal, err := NewWAL(walFile, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user