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:
Boris Nagaev committed 2025-08-30 14:13:44 -03:00
1 parent 6ffe257004
commit dee8ad3754
71 files changed
+361 -393

No files matched your search

+13 -14
View File
@@ -2,7 +2,6 @@ package graph
import (
"bytes"
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
@@ -44,7 +43,7 @@ const (
// info was added to the database.
func TestAddProof(t *testing.T) {
t.Parallel()
ctxb := context.Background()
ctxb := t.Context()
ctx := createTestCtxSingleNode(t, 0)
@@ -109,7 +108,7 @@ func TestIgnoreNodeAnnouncement(t *testing.T) {
}
copy(node.PubKeyBytes[:], pub.SerializeCompressed())
err := ctx.builder.AddNode(context.Background(), node)
err := ctx.builder.AddNode(t.Context(), node)
if !IsError(err, ErrIgnored) {
t.Fatalf("expected to get ErrIgnore, instead got: %v", err)
}
@@ -119,7 +118,7 @@ func TestIgnoreNodeAnnouncement(t *testing.T) {
// ignore a channel policy for a channel not in the graph.
func TestIgnoreChannelEdgePolicyForUnknownChannel(t *testing.T) {
t.Parallel()
ctxb := context.Background()
ctxb := t.Context()
const startingBlockHeight = 101
@@ -194,7 +193,7 @@ func TestIgnoreChannelEdgePolicyForUnknownChannel(t *testing.T) {
// confirmed on the stale chain, and resync to the main chain.
func TestWakeUpOnStaleBranch(t *testing.T) {
t.Parallel()
ctxb := context.Background()
ctxb := t.Context()
const startingBlockHeight = 101
ctx := createTestCtxSingleNode(t, startingBlockHeight)
@@ -354,7 +353,7 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
// Give time to process new blocks.
time.Sleep(time.Millisecond * 500)
selfNode, err := ctx.graph.SourceNode(context.Background())
selfNode, err := ctx.graph.SourceNode(t.Context())
require.NoError(t, err)
// Create new router with same graph database.
@@ -408,7 +407,7 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
// it is active.
func TestDisconnectedBlocks(t *testing.T) {
t.Parallel()
ctxb := context.Background()
ctxb := t.Context()
const startingBlockHeight = 101
ctx := createTestCtxSingleNode(t, startingBlockHeight)
@@ -609,7 +608,7 @@ func TestDisconnectedBlocks(t *testing.T) {
// ChannelRouter, then the channels are properly pruned.
func TestChansClosedOfflinePruneGraph(t *testing.T) {
t.Parallel()
ctxb := context.Background()
ctxb := t.Context()
const startingBlockHeight = 101
ctx := createTestCtxSingleNode(t, startingBlockHeight)
@@ -1037,7 +1036,7 @@ func testPruneChannelGraphDoubleDisabled(t *testing.T, assumeValid bool) {
// node announcements.
func TestIsStaleNode(t *testing.T) {
t.Parallel()
ctxb := context.Background()
ctxb := t.Context()
const startingBlockHeight = 101
ctx := createTestCtxSingleNode(t, startingBlockHeight)
@@ -1095,7 +1094,7 @@ func TestIsStaleNode(t *testing.T) {
Features: testFeatures,
}
copy(n1.PubKeyBytes[:], priv1.PubKey().SerializeCompressed())
if err := ctx.builder.AddNode(context.Background(), n1); err != nil {
if err := ctx.builder.AddNode(t.Context(), n1); err != nil {
t.Fatalf("could not add node: %v", err)
}
@@ -1117,7 +1116,7 @@ func TestIsStaleNode(t *testing.T) {
// channel announcements.
func TestIsKnownEdge(t *testing.T) {
t.Parallel()
ctxb := context.Background()
ctxb := t.Context()
const startingBlockHeight = 101
ctx := createTestCtxSingleNode(t, startingBlockHeight)
@@ -1167,7 +1166,7 @@ func TestIsKnownEdge(t *testing.T) {
// stale channel edge update announcements.
func TestIsStaleEdgePolicy(t *testing.T) {
t.Parallel()
ctxb := context.Background()
ctxb := t.Context()
const startingBlockHeight = 101
ctx := createTestCtxFromFile(t, startingBlockHeight, basicGraphFilePath)
@@ -1359,7 +1358,7 @@ func createTestCtxFromFile(t *testing.T,
func parseTestGraph(t *testing.T, useCache bool, path string) (
*testGraphInstance, error) {
ctx := context.Background()
ctx := t.Context()
graphJSON, err := os.ReadFile(path)
if err != nil {
@@ -1751,7 +1750,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
testChannels []*testChannel, source string) (*testGraphInstance,
error) {
ctx := context.Background()
ctx := t.Context()
// We'll use this fake address for the IP address of all the nodes in
// our tests. This value isn't needed for path finding so it doesn't