integration: allow specifying connection behavior
This commit is contained in:
parent
93cc7f36cf
commit
65d2b7a18c
1 changed files with 29 additions and 13 deletions
|
@ -34,6 +34,14 @@ const (
|
|||
// BlockVersion is the default block version used when generating
|
||||
// blocks.
|
||||
BlockVersion = 4
|
||||
|
||||
// DefaultMaxConnectionRetries is the default number of times we re-try
|
||||
// to connect to the node after starting it.
|
||||
DefaultMaxConnectionRetries = 20
|
||||
|
||||
// DefaultConnectionRetryTimeout is the default duration we wait between
|
||||
// two connection attempts.
|
||||
DefaultConnectionRetryTimeout = 50 * time.Millisecond
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -58,7 +66,7 @@ var (
|
|||
|
||||
// Used to protest concurrent access to above declared variables.
|
||||
harnessStateMtx sync.RWMutex
|
||||
|
||||
|
||||
// ListenAddressGenerator is a function that is used to generate two
|
||||
// listen addresses (host:port), one for the P2P listener and one for
|
||||
// the RPC listener. This is exported to allow overwriting of the
|
||||
|
@ -85,15 +93,22 @@ type Harness struct {
|
|||
// to.
|
||||
ActiveNet *chaincfg.Params
|
||||
|
||||
// MaxConnRetries is the maximum number of times we re-try to connect to
|
||||
// the node after starting it.
|
||||
MaxConnRetries int
|
||||
|
||||
// ConnectionRetryTimeout is the duration we wait between two connection
|
||||
// attempts.
|
||||
ConnectionRetryTimeout time.Duration
|
||||
|
||||
Node *rpcclient.Client
|
||||
node *node
|
||||
handlers *rpcclient.NotificationHandlers
|
||||
|
||||
wallet *memWallet
|
||||
|
||||
testNodeDir string
|
||||
maxConnRetries int
|
||||
nodeNum int
|
||||
testNodeDir string
|
||||
nodeNum int
|
||||
|
||||
sync.Mutex
|
||||
}
|
||||
|
@ -200,13 +215,14 @@ func New(activeNet *chaincfg.Params, handlers *rpcclient.NotificationHandlers,
|
|||
}
|
||||
|
||||
h := &Harness{
|
||||
handlers: handlers,
|
||||
node: node,
|
||||
maxConnRetries: 20,
|
||||
testNodeDir: nodeTestData,
|
||||
ActiveNet: activeNet,
|
||||
nodeNum: nodeNum,
|
||||
wallet: wallet,
|
||||
handlers: handlers,
|
||||
node: node,
|
||||
MaxConnRetries: DefaultMaxConnectionRetries,
|
||||
ConnectionRetryTimeout: DefaultConnectionRetryTimeout,
|
||||
testNodeDir: nodeTestData,
|
||||
ActiveNet: activeNet,
|
||||
nodeNum: nodeNum,
|
||||
wallet: wallet,
|
||||
}
|
||||
|
||||
// Track this newly created test instance within the package level
|
||||
|
@ -322,9 +338,9 @@ func (h *Harness) connectRPCClient() error {
|
|||
var err error
|
||||
|
||||
rpcConf := h.node.config.rpcConnConfig()
|
||||
for i := 0; i < h.maxConnRetries; i++ {
|
||||
for i := 0; i < h.MaxConnRetries; i++ {
|
||||
if client, err = rpcclient.New(&rpcConf, h.handlers); err != nil {
|
||||
time.Sleep(time.Duration(i) * 50 * time.Millisecond)
|
||||
time.Sleep(time.Duration(i) * h.ConnectionRetryTimeout)
|
||||
continue
|
||||
}
|
||||
break
|
||||
|
|
Loading…
Reference in a new issue