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.

135 lines
3.9 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
7 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
7 years ago
  1. /*
  2. package mock returns a Client implementation that
  3. accepts various (mock) implementations of the various methods.
  4. This implementation is useful for using in tests, when you don't
  5. need a real server, but want a high-level of control about
  6. the server response you want to mock (eg. error handling),
  7. or if you just want to record the calls to verify in your tests.
  8. For real clients, you probably want the "http" package. If you
  9. want to directly call a tendermint node in process, you can use the
  10. "local" package.
  11. */
  12. package mock
  13. import (
  14. "reflect"
  15. "github.com/tendermint/tendermint/rpc/client"
  16. "github.com/tendermint/tendermint/rpc/core"
  17. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  18. "github.com/tendermint/tendermint/types"
  19. cmn "github.com/tendermint/tmlibs/common"
  20. )
  21. // Client wraps arbitrary implementations of the various interfaces.
  22. //
  23. // We provide a few choices to mock out each one in this package.
  24. // Nothing hidden here, so no New function, just construct it from
  25. // some parts, and swap them out them during the tests.
  26. type Client struct {
  27. client.ABCIClient
  28. client.SignClient
  29. client.HistoryClient
  30. client.StatusClient
  31. client.EventsClient
  32. cmn.Service
  33. }
  34. var _ client.Client = Client{}
  35. // Call is used by recorders to save a call and response.
  36. // It can also be used to configure mock responses.
  37. //
  38. type Call struct {
  39. Name string
  40. Args interface{}
  41. Response interface{}
  42. Error error
  43. }
  44. // GetResponse will generate the apporiate response for us, when
  45. // using the Call struct to configure a Mock handler.
  46. //
  47. // When configuring a response, if only one of Response or Error is
  48. // set then that will always be returned. If both are set, then
  49. // we return Response if the Args match the set args, Error otherwise.
  50. func (c Call) GetResponse(args interface{}) (interface{}, error) {
  51. // handle the case with no response
  52. if c.Response == nil {
  53. if c.Error == nil {
  54. panic("Misconfigured call, you must set either Response or Error")
  55. }
  56. return nil, c.Error
  57. }
  58. // response without error
  59. if c.Error == nil {
  60. return c.Response, nil
  61. }
  62. // have both, we must check args....
  63. if reflect.DeepEqual(args, c.Args) {
  64. return c.Response, nil
  65. }
  66. return nil, c.Error
  67. }
  68. func (c Client) Status() (*ctypes.ResultStatus, error) {
  69. return core.Status()
  70. }
  71. func (c Client) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
  72. return core.ABCIInfo()
  73. }
  74. func (c Client) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
  75. return c.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions)
  76. }
  77. func (c Client) ABCIQueryWithOptions(path string, data cmn.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
  78. return core.ABCIQuery(path, data, opts.Height, opts.Trusted)
  79. }
  80. func (c Client) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
  81. return core.BroadcastTxCommit(tx)
  82. }
  83. func (c Client) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
  84. return core.BroadcastTxAsync(tx)
  85. }
  86. func (c Client) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
  87. return core.BroadcastTxSync(tx)
  88. }
  89. func (c Client) NetInfo() (*ctypes.ResultNetInfo, error) {
  90. return core.NetInfo()
  91. }
  92. func (c Client) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) {
  93. return core.UnsafeDialSeeds(seeds)
  94. }
  95. func (c Client) DialPeers(peers []string, persistent bool) (*ctypes.ResultDialPeers, error) {
  96. return core.UnsafeDialPeers(peers, persistent)
  97. }
  98. func (c Client) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) {
  99. return core.BlockchainInfo(minHeight, maxHeight)
  100. }
  101. func (c Client) Genesis() (*ctypes.ResultGenesis, error) {
  102. return core.Genesis()
  103. }
  104. func (c Client) Block(height *int64) (*ctypes.ResultBlock, error) {
  105. return core.Block(height)
  106. }
  107. func (c Client) Commit(height *int64) (*ctypes.ResultCommit, error) {
  108. return core.Commit(height)
  109. }
  110. func (c Client) Validators(height *int64) (*ctypes.ResultValidators, error) {
  111. return core.Validators(height)
  112. }