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
|
// BlockVersion is the default block version used when generating
|
||||||
// blocks.
|
// blocks.
|
||||||
BlockVersion = 4
|
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 (
|
var (
|
||||||
|
@ -58,7 +66,7 @@ var (
|
||||||
|
|
||||||
// Used to protest concurrent access to above declared variables.
|
// Used to protest concurrent access to above declared variables.
|
||||||
harnessStateMtx sync.RWMutex
|
harnessStateMtx sync.RWMutex
|
||||||
|
|
||||||
// ListenAddressGenerator is a function that is used to generate two
|
// ListenAddressGenerator is a function that is used to generate two
|
||||||
// listen addresses (host:port), one for the P2P listener and one for
|
// listen addresses (host:port), one for the P2P listener and one for
|
||||||
// the RPC listener. This is exported to allow overwriting of the
|
// the RPC listener. This is exported to allow overwriting of the
|
||||||
|
@ -85,15 +93,22 @@ type Harness struct {
|
||||||
// to.
|
// to.
|
||||||
ActiveNet *chaincfg.Params
|
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 *rpcclient.Client
|
||||||
node *node
|
node *node
|
||||||
handlers *rpcclient.NotificationHandlers
|
handlers *rpcclient.NotificationHandlers
|
||||||
|
|
||||||
wallet *memWallet
|
wallet *memWallet
|
||||||
|
|
||||||
testNodeDir string
|
testNodeDir string
|
||||||
maxConnRetries int
|
nodeNum int
|
||||||
nodeNum int
|
|
||||||
|
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
@ -200,13 +215,14 @@ func New(activeNet *chaincfg.Params, handlers *rpcclient.NotificationHandlers,
|
||||||
}
|
}
|
||||||
|
|
||||||
h := &Harness{
|
h := &Harness{
|
||||||
handlers: handlers,
|
handlers: handlers,
|
||||||
node: node,
|
node: node,
|
||||||
maxConnRetries: 20,
|
MaxConnRetries: DefaultMaxConnectionRetries,
|
||||||
testNodeDir: nodeTestData,
|
ConnectionRetryTimeout: DefaultConnectionRetryTimeout,
|
||||||
ActiveNet: activeNet,
|
testNodeDir: nodeTestData,
|
||||||
nodeNum: nodeNum,
|
ActiveNet: activeNet,
|
||||||
wallet: wallet,
|
nodeNum: nodeNum,
|
||||||
|
wallet: wallet,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track this newly created test instance within the package level
|
// Track this newly created test instance within the package level
|
||||||
|
@ -322,9 +338,9 @@ func (h *Harness) connectRPCClient() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
rpcConf := h.node.config.rpcConnConfig()
|
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 {
|
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
|
continue
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue