multi: context.Background() -> t.Context()
Use the new feature of Go 1.24, fix linter warnings. This change was produced by: - running golangci-lint run --fix - sed 's/context.Background/t.Context/' -i `git grep -l context.Background | grep test.go` - manually fixing broken tests - itest, lntest: use ht.Context() where ht or hn is available - in HarnessNode.Stop() we keep using context.Background(), because it is called from a cleanup handler in which t.Context() is canceled already.
This commit is contained in:
71 files changed
+361
-393
No files matched your search
@@ -1,7 +1,6 @@
|
||||
package itest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
@@ -65,7 +64,7 @@ func testChannelFundMaxError(ht *lntest.HarnessTest) {
|
||||
|
||||
// Calculate reserve amount for one channel.
|
||||
reserveResp, _ := alice.RPC.WalletKit.RequiredReserve(
|
||||
context.Background(), &walletrpc.RequiredReserveRequest{
|
||||
ht.Context(), &walletrpc.RequiredReserveRequest{
|
||||
AdditionalPublicChannels: 1,
|
||||
},
|
||||
)
|
||||
@@ -155,7 +154,7 @@ func testChannelFundMaxWalletAmount(ht *lntest.HarnessTest) {
|
||||
|
||||
// Calculate reserve amount for one channel.
|
||||
reserveResp, _ := alice.RPC.WalletKit.RequiredReserve(
|
||||
context.Background(), &walletrpc.RequiredReserveRequest{
|
||||
ht.Context(), &walletrpc.RequiredReserveRequest{
|
||||
AdditionalPublicChannels: 1,
|
||||
},
|
||||
)
|
||||
@@ -220,7 +219,7 @@ func testChannelFundMaxAnchorReserve(ht *lntest.HarnessTest) {
|
||||
|
||||
// Calculate reserve amount for one channel.
|
||||
reserveResp, _ := alice.RPC.WalletKit.RequiredReserve(
|
||||
context.Background(), &walletrpc.RequiredReserveRequest{
|
||||
ht.Context(), &walletrpc.RequiredReserveRequest{
|
||||
AdditionalPublicChannels: 1,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package itest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
@@ -104,7 +103,7 @@ func testChannelUtxoSelectionError(ht *lntest.HarnessTest) {
|
||||
|
||||
// Calculate reserve amount for one channel.
|
||||
reserveResp, _ := alice.RPC.WalletKit.RequiredReserve(
|
||||
context.Background(), &walletrpc.RequiredReserveRequest{
|
||||
ht.Context(), &walletrpc.RequiredReserveRequest{
|
||||
AdditionalPublicChannels: 1,
|
||||
},
|
||||
)
|
||||
@@ -198,7 +197,7 @@ func testUtxoSelectionSelectedValidChanSize(ht *lntest.HarnessTest) {
|
||||
|
||||
// Calculate reserve amount for one channel.
|
||||
reserveResp, _ := alice.RPC.WalletKit.RequiredReserve(
|
||||
context.Background(), &walletrpc.RequiredReserveRequest{
|
||||
ht.Context(), &walletrpc.RequiredReserveRequest{
|
||||
AdditionalPublicChannels: 1,
|
||||
},
|
||||
)
|
||||
@@ -240,7 +239,7 @@ func testUtxoSelectionSelectedValidChanReserve(ht *lntest.HarnessTest) {
|
||||
|
||||
// Calculate reserve amount for one channel.
|
||||
reserveResp, _ := alice.RPC.WalletKit.RequiredReserve(
|
||||
context.Background(), &walletrpc.RequiredReserveRequest{
|
||||
ht.Context(), &walletrpc.RequiredReserveRequest{
|
||||
AdditionalPublicChannels: 1,
|
||||
},
|
||||
)
|
||||
@@ -281,7 +280,7 @@ func testUtxoSelectionReserveFromSelected(ht *lntest.HarnessTest) {
|
||||
|
||||
// Calculate reserve amount for one channel.
|
||||
reserveResp, _ := alice.RPC.WalletKit.RequiredReserve(
|
||||
context.Background(), &walletrpc.RequiredReserveRequest{
|
||||
ht.Context(), &walletrpc.RequiredReserveRequest{
|
||||
AdditionalPublicChannels: 1,
|
||||
},
|
||||
)
|
||||
@@ -325,7 +324,7 @@ func testUtxoSelectionFundmax(ht *lntest.HarnessTest) {
|
||||
|
||||
// Calculate reserve amount for one channel.
|
||||
reserveResp, _ := alice.RPC.WalletKit.RequiredReserve(
|
||||
context.Background(), &walletrpc.RequiredReserveRequest{
|
||||
ht.Context(), &walletrpc.RequiredReserveRequest{
|
||||
AdditionalPublicChannels: 1,
|
||||
},
|
||||
)
|
||||
@@ -364,7 +363,7 @@ func testUtxoSelectionFundmaxReserve(ht *lntest.HarnessTest) {
|
||||
|
||||
// Calculate reserve amount for one channel.
|
||||
reserveResp, _ := alice.RPC.WalletKit.RequiredReserve(
|
||||
context.Background(), &walletrpc.RequiredReserveRequest{
|
||||
ht.Context(), &walletrpc.RequiredReserveRequest{
|
||||
AdditionalPublicChannels: 1,
|
||||
},
|
||||
)
|
||||
@@ -404,7 +403,7 @@ func testUtxoSelectionReuseUTXO(ht *lntest.HarnessTest) {
|
||||
|
||||
// Calculate reserve amount for one channel.
|
||||
reserveResp, _ := alice.RPC.WalletKit.RequiredReserve(
|
||||
context.Background(), &walletrpc.RequiredReserveRequest{
|
||||
ht.Context(), &walletrpc.RequiredReserveRequest{
|
||||
AdditionalPublicChannels: 1,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package itest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
@@ -1164,7 +1163,7 @@ func ensurePolicy(ht *lntest.HarnessTest, alice, peer *node.HarnessNode,
|
||||
|
||||
channel := ht.AssertChannelExists(peer, chanPoint)
|
||||
policy, err := peer.RPC.LN.GetChanInfo(
|
||||
context.Background(), &lnrpc.ChanInfoRequest{
|
||||
ht.Context(), &lnrpc.ChanInfoRequest{
|
||||
ChanId: channel.ChanId,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -21,7 +21,7 @@ func testGraphMigration(ht *lntest.HarnessTest) {
|
||||
ht.Skip("not running with test_native_sql tag")
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := ht.Context()
|
||||
alice := ht.NewNodeWithCoins("Alice", nil)
|
||||
|
||||
// Make sure we run the test with SQLite or Postgres.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package itest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
@@ -47,7 +46,7 @@ func testInvoiceHtlcModifierBasic(ht *lntest.HarnessTest) {
|
||||
// Make sure we get an error if we try to register a second modifier and
|
||||
// then try to use it (the error won't be returned on connect, only on
|
||||
// the first _read_ interaction on the stream).
|
||||
mod2, err := carol.RPC.Invoice.HtlcModifier(context.Background())
|
||||
mod2, err := carol.RPC.Invoice.HtlcModifier(ht.Context())
|
||||
require.NoError(ht, err)
|
||||
_, err = mod2.Recv()
|
||||
require.ErrorContains(
|
||||
|
||||
@@ -1400,7 +1400,7 @@ func testGRPCNotFound(ht *lntest.HarnessTest) {
|
||||
// during a reorg. A reorg notification is produced after a reorg affects the
|
||||
// block which has produced a spending notification for this registration.
|
||||
func testReorgNotifications(ht *lntest.HarnessTest) {
|
||||
ctxb := context.Background()
|
||||
ctxb := ht.Context()
|
||||
const timeout = wait.DefaultTimeout
|
||||
|
||||
alice := ht.NewNodeWithCoins("Alice", nil)
|
||||
@@ -1599,7 +1599,7 @@ func testReorgNotifications(ht *lntest.HarnessTest) {
|
||||
func testEstimateFee(ht *lntest.HarnessTest) {
|
||||
alice := ht.NewNode("Alice", nil)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := ht.Context()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
||||
@@ -1081,7 +1081,7 @@ func sendPaymentInterceptAndCancel(ht *lntest.HarnessTest,
|
||||
|
||||
// We initiate a payment from Alice and define the payment context
|
||||
// cancellable.
|
||||
ctx, cancelPaymentContext := context.WithCancel(context.Background())
|
||||
ctx, cancelPaymentContext := context.WithCancel(ht.Context())
|
||||
var paymentStream rpc.PaymentClient
|
||||
go func() {
|
||||
req := &routerrpc.SendPaymentRequest{
|
||||
|
||||
@@ -335,7 +335,7 @@ type blindedForwardTest struct {
|
||||
func newBlindedForwardTest(ht *lntest.HarnessTest) (context.Context,
|
||||
*blindedForwardTest) {
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(ht.Context())
|
||||
|
||||
return ctx, &blindedForwardTest{
|
||||
ht: ht,
|
||||
|
||||
@@ -220,7 +220,7 @@ func middlewareInterceptionTest(t *testing.T,
|
||||
|
||||
// Everything we test here should be executed in a matter of
|
||||
// milliseconds, so we can use one single timeout context for all calls.
|
||||
ctxb := context.Background()
|
||||
ctxb := t.Context()
|
||||
ctxc, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -372,7 +372,7 @@ func middlewareResponseManipulationTest(t *testing.T,
|
||||
|
||||
// Everything we test here should be executed in a matter of
|
||||
// milliseconds, so we can use one single timeout context for all calls.
|
||||
ctxb := context.Background()
|
||||
ctxb := t.Context()
|
||||
ctxc, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -489,7 +489,7 @@ func middlewareRequestManipulationTest(t *testing.T, node *node.HarnessNode,
|
||||
|
||||
// Everything we test here should be executed in a matter of
|
||||
// milliseconds, so we can use one single timeout context for all calls.
|
||||
ctxb := context.Background()
|
||||
ctxb := t.Context()
|
||||
ctxc, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -582,7 +582,7 @@ func middlewareMandatoryTest(ht *lntest.HarnessTest, node *node.HarnessNode) {
|
||||
err = node.WaitUntilServerActive()
|
||||
require.NoError(ht, err)
|
||||
|
||||
ctxb := context.Background()
|
||||
ctxb := ht.Context()
|
||||
ctxc, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package itest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
@@ -500,7 +499,7 @@ func runSignVerifyMessage(ht *lntest.HarnessTest, alice *node.HarnessNode) {
|
||||
|
||||
expectedErr := "tag can only be used when the Schnorr signature " +
|
||||
"option is set"
|
||||
ctxt := context.Background()
|
||||
ctxt := ht.Context()
|
||||
_, err := alice.RPC.Signer.SignMessage(ctxt, signMsgReq)
|
||||
require.ErrorContains(ht, err, expectedErr)
|
||||
|
||||
|
||||
Reference in new issue
Block a user