From 5177ec2f849983d3be66775b6bc3a6a55b0e2ed6 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Sat, 17 Jul 2021 12:01:39 +0200 Subject: [PATCH] lntest: create persistent connection This commit adds a ConnectNodesPerm function to the itest NetworkHarness so that persistent connections between nodes can be mocked. --- lntest/harness.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lntest/harness.go b/lntest/harness.go index 485a2b9af..105f5c269 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -670,13 +670,31 @@ func (n *NetworkHarness) EnsureConnected(t *testing.T, a, b *HarnessNode) { ) } -// ConnectNodes establishes an encrypted+authenticated p2p connection from node +// ConnectNodes attempts to create a connection between nodes a and b. +func (n *NetworkHarness) ConnectNodes(t *testing.T, a, b *HarnessNode) { + n.connectNodes(t, a, b, false) +} + +// ConnectNodesPerm attempts to connect nodes a and b and sets node b as +// a peer that node a should persistently attempt to reconnect to if they +// become disconnected. +func (n *NetworkHarness) ConnectNodesPerm(t *testing.T, + a, b *HarnessNode) { + + n.connectNodes(t, a, b, true) +} + +// connectNodes establishes an encrypted+authenticated p2p connection from node // a towards node b. The function will return a non-nil error if the connection -// was unable to be established. +// was unable to be established. If the perm parameter is set to true then +// node a will persistently attempt to reconnect to node b if they get +// disconnected. // // NOTE: This function may block for up to 15-seconds as it will not return // until the new connection is detected as being known to both nodes. -func (n *NetworkHarness) ConnectNodes(t *testing.T, a, b *HarnessNode) { +func (n *NetworkHarness) connectNodes(t *testing.T, a, b *HarnessNode, + perm bool) { + ctxb := context.Background() ctx, cancel := context.WithTimeout(ctxb, DefaultTimeout) defer cancel() @@ -692,6 +710,7 @@ func (n *NetworkHarness) ConnectNodes(t *testing.T, a, b *HarnessNode) { Pubkey: bobInfo.IdentityPubkey, Host: b.Cfg.P2PAddr(), }, + Perm: perm, } err = n.connect(ctx, req, a)