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

+2 -3
View File
@@ -1,7 +1,6 @@
package autopilot
import (
"context"
"fmt"
"testing"
@@ -32,7 +31,7 @@ func TestBetweennessCentralityMetricConstruction(t *testing.T) {
// Tests that empty graph results in empty centrality result.
func TestBetweennessCentralityEmptyGraph(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
centralityMetric, err := NewBetweennessCentralityMetric(1)
require.NoError(
@@ -64,7 +63,7 @@ func TestBetweennessCentralityEmptyGraph(t *testing.T) {
// Test betweenness centrality calculating using an example graph.
func TestBetweennessCentralityWithNonEmptyGraph(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
workers := []int{1, 3, 9, 100}
+1 -2
View File
@@ -1,7 +1,6 @@
package autopilot_test
import (
"context"
"testing"
"github.com/btcsuite/btcd/btcec/v2"
@@ -23,7 +22,7 @@ func randKey() (*btcec.PublicKey, error) {
// ExternalScoreAttachment correctly reflects the scores we set last.
func TestSetNodeScores(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
const name = "externalscore"
+4 -4
View File
@@ -76,7 +76,7 @@ var chanGraphs = []struct {
// empty graph, the NodeSores function always returns a score of 0.
func TestPrefAttachmentSelectEmptyGraph(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
prefAttach := NewPrefAttachment()
// Create a random public key, which we will query to get a score for.
@@ -116,7 +116,7 @@ func TestPrefAttachmentSelectEmptyGraph(t *testing.T) {
// and the funds are appropriately allocated across each peer.
func TestPrefAttachmentSelectTwoVertexes(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
prand.Seed(time.Now().Unix())
@@ -203,7 +203,7 @@ func TestPrefAttachmentSelectTwoVertexes(t *testing.T) {
// allocate all funds to each vertex (up to the max channel size).
func TestPrefAttachmentSelectGreedyAllocation(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
prand.Seed(time.Now().Unix())
@@ -316,7 +316,7 @@ func TestPrefAttachmentSelectGreedyAllocation(t *testing.T) {
// of zero during scoring.
func TestPrefAttachmentSelectSkipNodes(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
prand.Seed(time.Now().Unix())
+1 -2
View File
@@ -1,7 +1,6 @@
package autopilot
import (
"context"
"testing"
"github.com/btcsuite/btcd/btcec/v2"
@@ -59,7 +58,7 @@ func testTopCentrality(t *testing.T, graph testGraph,
// Attempt to get centrality scores and expect
// that the result equals with the expected set.
scores, err := topCentrality.NodeScores(
context.Background(), graph, channels, chanSize, nodes,
t.Context(), graph, channels, chanSize, nodes,
)
require.NoError(t, err)