integration: allow specifying connection behavior

This commit is contained in:
Oliver Gugger 2020-11-11 14:29:17 +01:00
parent 93cc7f36cf
commit 65d2b7a18c
No known key found for this signature in database
GPG key ID: 8E4256593F177720

View file

@ -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 (
@ -85,6 +93,14 @@ 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
@ -92,7 +108,6 @@ type Harness struct {
wallet *memWallet wallet *memWallet
testNodeDir string testNodeDir string
maxConnRetries int
nodeNum int nodeNum int
sync.Mutex sync.Mutex
@ -202,7 +217,8 @@ func New(activeNet *chaincfg.Params, handlers *rpcclient.NotificationHandlers,
h := &Harness{ h := &Harness{
handlers: handlers, handlers: handlers,
node: node, node: node,
maxConnRetries: 20, MaxConnRetries: DefaultMaxConnectionRetries,
ConnectionRetryTimeout: DefaultConnectionRetryTimeout,
testNodeDir: nodeTestData, testNodeDir: nodeTestData,
ActiveNet: activeNet, ActiveNet: activeNet,
nodeNum: nodeNum, nodeNum: nodeNum,
@ -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