2017-02-22 16:39:01 +01:00
|
|
|
/*
|
|
|
|
package mock returns a Client implementation that
|
|
|
|
accepts various (mock) implementations of the various methods.
|
|
|
|
|
|
|
|
This implementation is useful for using in tests, when you don't
|
|
|
|
need a real server, but want a high-level of control about
|
|
|
|
the server response you want to mock (eg. error handling),
|
|
|
|
or if you just want to record the calls to verify in your tests.
|
|
|
|
|
|
|
|
For real clients, you probably want the "http" package. If you
|
|
|
|
want to directly call a tendermint node in process, you can use the
|
|
|
|
"local" package.
|
|
|
|
*/
|
|
|
|
package mock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
|
2017-04-21 18:13:25 -04:00
|
|
|
data "github.com/tendermint/go-wire/data"
|
2017-04-26 19:57:33 -04:00
|
|
|
"github.com/tendermint/tendermint/rpc/client"
|
|
|
|
"github.com/tendermint/tendermint/rpc/core"
|
|
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
2017-02-22 16:39:01 +01:00
|
|
|
"github.com/tendermint/tendermint/types"
|
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
2017-06-26 19:00:30 +04:00
|
|
|
cmn "github.com/tendermint/tmlibs/common"
|
2017-02-22 16:39:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Client wraps arbitrary implementations of the various interfaces.
|
|
|
|
//
|
|
|
|
// We provide a few choices to mock out each one in this package.
|
|
|
|
// Nothing hidden here, so no New function, just construct it from
|
|
|
|
// some parts, and swap them out them during the tests.
|
|
|
|
type Client struct {
|
|
|
|
client.ABCIClient
|
|
|
|
client.SignClient
|
|
|
|
client.HistoryClient
|
|
|
|
client.StatusClient
|
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
2017-06-26 19:00:30 +04:00
|
|
|
client.EventsClient
|
|
|
|
cmn.Service
|
2017-02-22 16:39:01 +01:00
|
|
|
}
|
|
|
|
|
2017-10-13 00:11:20 -06:00
|
|
|
var _ client.Client = Client{}
|
2017-02-22 16:39:01 +01:00
|
|
|
|
|
|
|
// Call is used by recorders to save a call and response.
|
|
|
|
// It can also be used to configure mock responses.
|
|
|
|
//
|
|
|
|
type Call struct {
|
|
|
|
Name string
|
|
|
|
Args interface{}
|
|
|
|
Response interface{}
|
|
|
|
Error error
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetResponse will generate the apporiate response for us, when
|
|
|
|
// using the Call struct to configure a Mock handler.
|
|
|
|
//
|
|
|
|
// When configuring a response, if only one of Response or Error is
|
|
|
|
// set then that will always be returned. If both are set, then
|
|
|
|
// we return Response if the Args match the set args, Error otherwise.
|
|
|
|
func (c Call) GetResponse(args interface{}) (interface{}, error) {
|
|
|
|
// handle the case with no response
|
|
|
|
if c.Response == nil {
|
|
|
|
if c.Error == nil {
|
|
|
|
panic("Misconfigured call, you must set either Response or Error")
|
|
|
|
}
|
|
|
|
return nil, c.Error
|
|
|
|
}
|
|
|
|
// response without error
|
|
|
|
if c.Error == nil {
|
|
|
|
return c.Response, nil
|
|
|
|
}
|
|
|
|
// have both, we must check args....
|
|
|
|
if reflect.DeepEqual(args, c.Args) {
|
|
|
|
return c.Response, nil
|
|
|
|
}
|
|
|
|
return nil, c.Error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Client) Status() (*ctypes.ResultStatus, error) {
|
|
|
|
return core.Status()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Client) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
|
|
|
return core.ABCIInfo()
|
|
|
|
}
|
|
|
|
|
2017-10-11 01:31:31 +04:00
|
|
|
func (c Client) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
|
2017-10-11 16:50:11 +04:00
|
|
|
return c.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions)
|
2017-10-11 01:31:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c Client) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
|
2017-10-11 16:50:11 +04:00
|
|
|
return core.ABCIQuery(path, data, opts.Height, opts.Trusted)
|
2017-02-22 16:39:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c Client) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
|
|
|
return core.BroadcastTxCommit(tx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Client) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
|
|
|
return core.BroadcastTxAsync(tx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Client) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
|
|
|
return core.BroadcastTxSync(tx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Client) NetInfo() (*ctypes.ResultNetInfo, error) {
|
|
|
|
return core.NetInfo()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Client) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) {
|
|
|
|
return core.UnsafeDialSeeds(seeds)
|
|
|
|
}
|
|
|
|
|
2017-11-30 13:08:38 -06:00
|
|
|
func (c Client) BlockchainInfo(minHeight, maxHeight uint64) (*ctypes.ResultBlockchainInfo, error) {
|
2017-02-22 16:39:01 +01:00
|
|
|
return core.BlockchainInfo(minHeight, maxHeight)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Client) Genesis() (*ctypes.ResultGenesis, error) {
|
|
|
|
return core.Genesis()
|
|
|
|
}
|
|
|
|
|
2017-11-30 13:08:38 -06:00
|
|
|
func (c Client) Block(height *uint64) (*ctypes.ResultBlock, error) {
|
2017-02-22 16:39:01 +01:00
|
|
|
return core.Block(height)
|
|
|
|
}
|
|
|
|
|
2017-11-30 13:08:38 -06:00
|
|
|
func (c Client) Commit(height *uint64) (*ctypes.ResultCommit, error) {
|
2017-02-22 16:39:01 +01:00
|
|
|
return core.Commit(height)
|
|
|
|
}
|
|
|
|
|
2017-11-30 13:08:38 -06:00
|
|
|
func (c Client) Validators(height *uint64) (*ctypes.ResultValidators, error) {
|
2017-08-21 18:11:16 -04:00
|
|
|
return core.Validators(height)
|
2017-02-22 16:39:01 +01:00
|
|
|
}
|