You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
6.4 KiB

new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. package consensus
  2. import (
  3. "encoding/binary"
  4. "testing"
  5. "time"
  6. abci "github.com/tendermint/abci/types"
  7. "github.com/tendermint/tendermint/types"
  8. cmn "github.com/tendermint/tmlibs/common"
  9. )
  10. func init() {
  11. config = ResetConfig("consensus_mempool_test")
  12. }
  13. func TestNoProgressUntilTxsAvailable(t *testing.T) {
  14. config := ResetConfig("consensus_mempool_txs_available_test")
  15. config.Consensus.CreateEmptyBlocks = false
  16. state, privVals := randGenesisState(1, false, 10)
  17. cs := newConsensusStateWithConfig(config, state, privVals[0], NewCounterApplication())
  18. cs.mempool.EnableTxsAvailable()
  19. height, round := cs.Height, cs.Round
  20. newBlockCh := subscribe(cs.eventBus, types.EventQueryNewBlock)
  21. startTestRound(cs, height, round)
  22. ensureNewStep(newBlockCh) // first block gets committed
  23. ensureNoNewStep(newBlockCh)
  24. deliverTxsRange(cs, 0, 1)
  25. ensureNewStep(newBlockCh) // commit txs
  26. ensureNewStep(newBlockCh) // commit updated app hash
  27. ensureNoNewStep(newBlockCh)
  28. }
  29. func TestProgressAfterCreateEmptyBlocksInterval(t *testing.T) {
  30. config := ResetConfig("consensus_mempool_txs_available_test")
  31. config.Consensus.CreateEmptyBlocksInterval = int(ensureTimeout.Seconds())
  32. state, privVals := randGenesisState(1, false, 10)
  33. cs := newConsensusStateWithConfig(config, state, privVals[0], NewCounterApplication())
  34. cs.mempool.EnableTxsAvailable()
  35. height, round := cs.Height, cs.Round
  36. newBlockCh := subscribe(cs.eventBus, types.EventQueryNewBlock)
  37. startTestRound(cs, height, round)
  38. ensureNewStep(newBlockCh) // first block gets committed
  39. ensureNoNewStep(newBlockCh) // then we dont make a block ...
  40. ensureNewStep(newBlockCh) // until the CreateEmptyBlocksInterval has passed
  41. }
  42. func TestProgressInHigherRound(t *testing.T) {
  43. config := ResetConfig("consensus_mempool_txs_available_test")
  44. config.Consensus.CreateEmptyBlocks = false
  45. state, privVals := randGenesisState(1, false, 10)
  46. cs := newConsensusStateWithConfig(config, state, privVals[0], NewCounterApplication())
  47. cs.mempool.EnableTxsAvailable()
  48. height, round := cs.Height, cs.Round
  49. newBlockCh := subscribe(cs.eventBus, types.EventQueryNewBlock)
  50. newRoundCh := subscribe(cs.eventBus, types.EventQueryNewRound)
  51. timeoutCh := subscribe(cs.eventBus, types.EventQueryTimeoutPropose)
  52. cs.setProposal = func(proposal *types.Proposal) error {
  53. if cs.Height == 2 && cs.Round == 0 {
  54. // dont set the proposal in round 0 so we timeout and
  55. // go to next round
  56. cs.Logger.Info("Ignoring set proposal at height 2, round 0")
  57. return nil
  58. }
  59. return cs.defaultSetProposal(proposal)
  60. }
  61. startTestRound(cs, height, round)
  62. ensureNewStep(newRoundCh) // first round at first height
  63. ensureNewStep(newBlockCh) // first block gets committed
  64. ensureNewStep(newRoundCh) // first round at next height
  65. deliverTxsRange(cs, 0, 1) // we deliver txs, but dont set a proposal so we get the next round
  66. <-timeoutCh
  67. ensureNewStep(newRoundCh) // wait for the next round
  68. ensureNewStep(newBlockCh) // now we can commit the block
  69. }
  70. func deliverTxsRange(cs *ConsensusState, start, end int) {
  71. // Deliver some txs.
  72. for i := start; i < end; i++ {
  73. txBytes := make([]byte, 8)
  74. binary.BigEndian.PutUint64(txBytes, uint64(i))
  75. err := cs.mempool.CheckTx(txBytes, nil)
  76. if err != nil {
  77. panic(cmn.Fmt("Error after CheckTx: %v", err))
  78. }
  79. }
  80. }
  81. func TestTxConcurrentWithCommit(t *testing.T) {
  82. state, privVals := randGenesisState(1, false, 10)
  83. cs := newConsensusState(state, privVals[0], NewCounterApplication())
  84. height, round := cs.Height, cs.Round
  85. newBlockCh := subscribe(cs.eventBus, types.EventQueryNewBlock)
  86. NTxs := 10000
  87. go deliverTxsRange(cs, 0, NTxs)
  88. startTestRound(cs, height, round)
  89. ticker := time.NewTicker(time.Second * 20)
  90. for nTxs := 0; nTxs < NTxs; {
  91. select {
  92. case b := <-newBlockCh:
  93. nTxs += b.(types.TMEventData).Unwrap().(types.EventDataNewBlock).Block.Header.NumTxs
  94. case <-ticker.C:
  95. panic("Timed out waiting to commit blocks with transactions")
  96. }
  97. }
  98. }
  99. func TestRmBadTx(t *testing.T) {
  100. state, privVals := randGenesisState(1, false, 10)
  101. app := NewCounterApplication()
  102. cs := newConsensusState(state, privVals[0], app)
  103. // increment the counter by 1
  104. txBytes := make([]byte, 8)
  105. binary.BigEndian.PutUint64(txBytes, uint64(0))
  106. app.DeliverTx(txBytes)
  107. app.Commit()
  108. emptyMempoolCh := make(chan struct{})
  109. checkTxRespCh := make(chan struct{})
  110. go func() {
  111. // Try to send the tx through the mempool.
  112. // CheckTx should not err, but the app should return a bad abci code
  113. // and the tx should get removed from the pool
  114. err := cs.mempool.CheckTx(txBytes, func(r *abci.Response) {
  115. if r.GetCheckTx().Code != abci.CodeType_BadNonce {
  116. t.Fatalf("expected checktx to return bad nonce, got %v", r)
  117. }
  118. checkTxRespCh <- struct{}{}
  119. })
  120. if err != nil {
  121. t.Fatal("Error after CheckTx: %v", err)
  122. }
  123. // check for the tx
  124. for {
  125. txs := cs.mempool.Reap(1)
  126. if len(txs) == 0 {
  127. emptyMempoolCh <- struct{}{}
  128. }
  129. time.Sleep(10 * time.Millisecond)
  130. }
  131. }()
  132. // Wait until the tx returns
  133. ticker := time.After(time.Second * 5)
  134. select {
  135. case <-checkTxRespCh:
  136. // success
  137. case <-ticker:
  138. t.Fatalf("Timed out waiting for tx to return")
  139. }
  140. // Wait until the tx is removed
  141. ticker = time.After(time.Second * 5)
  142. select {
  143. case <-emptyMempoolCh:
  144. // success
  145. case <-ticker:
  146. t.Fatalf("Timed out waiting for tx to be removed")
  147. }
  148. }
  149. // CounterApplication that maintains a mempool state and resets it upon commit
  150. type CounterApplication struct {
  151. abci.BaseApplication
  152. txCount int
  153. mempoolTxCount int
  154. }
  155. func NewCounterApplication() *CounterApplication {
  156. return &CounterApplication{}
  157. }
  158. func (app *CounterApplication) Info(req abci.RequestInfo) abci.ResponseInfo {
  159. return abci.ResponseInfo{Data: cmn.Fmt("txs:%v", app.txCount)}
  160. }
  161. func (app *CounterApplication) DeliverTx(tx []byte) abci.Result {
  162. return runTx(tx, &app.txCount)
  163. }
  164. func (app *CounterApplication) CheckTx(tx []byte) abci.Result {
  165. return runTx(tx, &app.mempoolTxCount)
  166. }
  167. func runTx(tx []byte, countPtr *int) abci.Result {
  168. count := *countPtr
  169. tx8 := make([]byte, 8)
  170. copy(tx8[len(tx8)-len(tx):], tx)
  171. txValue := binary.BigEndian.Uint64(tx8)
  172. if txValue != uint64(count) {
  173. return abci.ErrBadNonce.AppendLog(cmn.Fmt("Invalid nonce. Expected %v, got %v", count, txValue))
  174. }
  175. *countPtr += 1
  176. return abci.OK
  177. }
  178. func (app *CounterApplication) Commit() abci.Result {
  179. app.mempoolTxCount = app.txCount
  180. if app.txCount == 0 {
  181. return abci.OK
  182. } else {
  183. hash := make([]byte, 8)
  184. binary.BigEndian.PutUint64(hash, uint64(app.txCount))
  185. return abci.NewResultOK(hash, "")
  186. }
  187. }