From 13399e9e81f90a61b0cb96a45a3c6cec78a794ed Mon Sep 17 00:00:00 2001 From: Matheus Degiovani Date: Fri, 21 Jul 2023 16:24:30 -0300 Subject: [PATCH] itest: bind to local addr in network test This makes the test work even if the local OS has no outside network connections available or if DNS lookups are failing. --- docs/release-notes/release-notes-0.17.0.md | 3 +++ itest/lnd_network_test.go | 14 ++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/release-notes/release-notes-0.17.0.md b/docs/release-notes/release-notes-0.17.0.md index 61b5d0eca..cccf82e64 100644 --- a/docs/release-notes/release-notes-0.17.0.md +++ b/docs/release-notes/release-notes-0.17.0.md @@ -148,6 +148,9 @@ unlock or create. * [Simplify fuzz tests](https://github.com/lightningnetwork/lnd/pull/7709) using the `require` package. +* [Removed](https://github.com/lightningnetwork/lnd/pull/7854) need for an + active internet connection for the network connection itest. + ## `lncli` * Added ability to use [ENV variables to override `lncli` global flags](https://github.com/lightningnetwork/lnd/pull/7693). Flags will have preference over ENVs. diff --git a/itest/lnd_network_test.go b/itest/lnd_network_test.go index 3b6a4a8e2..b4c73af60 100644 --- a/itest/lnd_network_test.go +++ b/itest/lnd_network_test.go @@ -17,14 +17,20 @@ import ( // effect. It creates a node with a small connection timeout value, and // connects it to a non-routable IP address. func testNetworkConnectionTimeout(ht *lntest.HarnessTest) { + // Bind to a random port on localhost but never actually accept any + // connections. This makes any connection attempts timeout. + l, err := net.Listen("tcp", "127.0.0.1:0") + require.NoError(ht, err) + defer l.Close() + var ( // testPub is a random public key for testing only. testPub = "0332bda7da70fefe4b6ab92f53b3c4f4ee7999" + "f312284a8e89c8670bb3f67dbee2" - // testHost is a reachable IP address with an unreachable port - // that's used for testing only. - testHost = "lightning.engineering:81" + // testHost is the previously bound address that will never + // accept any conns. + testHost = l.Addr().String() ) // First, test the global timeout settings. @@ -62,7 +68,7 @@ func testNetworkConnectionTimeout(ht *lntest.HarnessTest) { dave := ht.NewNode("Dave", nil) // Try to connect Dave to a non-routable IP address, using a timeout - // value of 1ms, which should give us a timeout error immediately. + // value of 1s, which should give us a timeout error immediately. req = &lnrpc.ConnectPeerRequest{ Addr: &lnrpc.LightningAddress{ Pubkey: testPub,