From 8e6ef3f5672c04293c829de5b87dc24c31dfd99e Mon Sep 17 00:00:00 2001 From: positiveblue Date: Thu, 23 Feb 2023 02:26:02 -0800 Subject: [PATCH] itest: add default context timeout to all itests --- itest/litd_firewall_test.go | 8 ++++---- itest/litd_mode_integrated_test.go | 4 ++-- itest/litd_mode_remote_test.go | 4 +--- itest/test_harness.go | 12 ++++++++++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/itest/litd_firewall_test.go b/itest/litd_firewall_test.go index 7d64a700..c77f1218 100644 --- a/itest/litd_firewall_test.go +++ b/itest/litd_firewall_test.go @@ -378,8 +378,8 @@ func assertStatusErr(t *testing.T, err error, code codes.Code) { // testFirewallRules tests that the various firewall rules are enforced // correctly. -func testFirewallRules(net *NetworkHarness, t *harnessTest) { - ctx := context.Background() +func testFirewallRules(ctx context.Context, net *NetworkHarness, + t *harnessTest) { // Some very basic functionality tests to make sure lnd is working fine // in integrated mode. @@ -1142,8 +1142,8 @@ func testPeerAndChannelRestrictRules(net *NetworkHarness, t *harnessTest) { require.NoError(t.t, err) } -func testLargeHttpHeader(net *NetworkHarness, t *harnessTest) { - ctx := context.Background() +func testLargeHttpHeader(ctx context.Context, net *NetworkHarness, + t *harnessTest) { // First we add all LND's permissions so that any call we make to LND to // test that the connection is working will succeed. diff --git a/itest/litd_mode_integrated_test.go b/itest/litd_mode_integrated_test.go index 4e930dd5..fa971f69 100644 --- a/itest/litd_mode_integrated_test.go +++ b/itest/litd_mode_integrated_test.go @@ -259,8 +259,8 @@ var ( // testModeIntegrated makes sure that in integrated mode all daemons work // correctly. -func testModeIntegrated(net *NetworkHarness, t *harnessTest) { - ctx := context.Background() +func testModeIntegrated(ctx context.Context, net *NetworkHarness, + t *harnessTest) { // Some very basic functionality tests to make sure lnd is working fine // in integrated mode. diff --git a/itest/litd_mode_remote_test.go b/itest/litd_mode_remote_test.go index 1713b50e..9a987c64 100644 --- a/itest/litd_mode_remote_test.go +++ b/itest/litd_mode_remote_test.go @@ -13,9 +13,7 @@ import ( ) // testModeRemote makes sure that in remote mode all daemons work correctly. -func testModeRemote(net *NetworkHarness, t *harnessTest) { - ctx := context.Background() - +func testModeRemote(ctx context.Context, net *NetworkHarness, t *harnessTest) { // Some very basic functionality tests to make sure lnd is working fine // in remote mode. net.SendCoins(t.t, btcutil.SatoshiPerBitcoin, net.Bob) diff --git a/itest/test_harness.go b/itest/test_harness.go index 5fda89d5..c565b03f 100644 --- a/itest/test_harness.go +++ b/itest/test_harness.go @@ -2,6 +2,7 @@ package itest import ( "bytes" + "context" "flag" "fmt" "testing" @@ -25,6 +26,8 @@ var ( ) slowMineDelay = 20 * time.Millisecond + + defaultITestTimeout = 10 * time.Minute ) const ( @@ -92,7 +95,12 @@ func (h *harnessTest) RunTestCase(testCase *testCase) { } }() - testCase.test(h.lndHarness, h) + ctxt, cancel := context.WithTimeout( + context.Background(), defaultITestTimeout, + ) + defer cancel() + + testCase.test(ctxt, h.lndHarness, h) } func (h *harnessTest) Logf(format string, args ...interface{}) { @@ -118,7 +126,7 @@ func getLitdBinary() string { type testCase struct { name string - test func(net *NetworkHarness, t *harnessTest) + test func(ctx context.Context, net *NetworkHarness, t *harnessTest) } // waitForNTxsInMempool polls until finding the desired number of transactions