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
// 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 (
@ -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