Skip to content

Commit dee8ad3

Browse files
committed
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.
1 parent 6ffe257 commit dee8ad3

File tree

71 files changed

+361
-393
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+361
-393
lines changed

accessman_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package lnd
22

33
import (
4-
"context"
54
"testing"
65

76
"github.com/btcsuite/btcd/btcec/v2"
@@ -490,7 +489,7 @@ func TestAssignPeerPermsBypassExisting(t *testing.T) {
490489
func TestHasPeer(t *testing.T) {
491490
t.Parallel()
492491

493-
ctx := context.Background()
492+
ctx := t.Context()
494493

495494
// Create a testing accessMan.
496495
a := &accessMan{
@@ -708,7 +707,7 @@ func TestAddPeerAccessOutbound(t *testing.T) {
708707
// accessman's internal state based on the peer's status.
709708
func TestRemovePeerAccess(t *testing.T) {
710709
t.Parallel()
711-
ctx := context.Background()
710+
ctx := t.Context()
712711

713712
// Create a testing accessMan.
714713
a := &accessMan{

autopilot/betweenness_centrality_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package autopilot
22

33
import (
4-
"context"
54
"fmt"
65
"testing"
76

@@ -32,7 +31,7 @@ func TestBetweennessCentralityMetricConstruction(t *testing.T) {
3231
// Tests that empty graph results in empty centrality result.
3332
func TestBetweennessCentralityEmptyGraph(t *testing.T) {
3433
t.Parallel()
35-
ctx := context.Background()
34+
ctx := t.Context()
3635

3736
centralityMetric, err := NewBetweennessCentralityMetric(1)
3837
require.NoError(
@@ -64,7 +63,7 @@ func TestBetweennessCentralityEmptyGraph(t *testing.T) {
6463
// Test betweenness centrality calculating using an example graph.
6564
func TestBetweennessCentralityWithNonEmptyGraph(t *testing.T) {
6665
t.Parallel()
67-
ctx := context.Background()
66+
ctx := t.Context()
6867

6968
workers := []int{1, 3, 9, 100}
7069

autopilot/externalscoreattach_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package autopilot_test
22

33
import (
4-
"context"
54
"testing"
65

76
"github.com/btcsuite/btcd/btcec/v2"
@@ -23,7 +22,7 @@ func randKey() (*btcec.PublicKey, error) {
2322
// ExternalScoreAttachment correctly reflects the scores we set last.
2423
func TestSetNodeScores(t *testing.T) {
2524
t.Parallel()
26-
ctx := context.Background()
25+
ctx := t.Context()
2726

2827
const name = "externalscore"
2928

autopilot/prefattach_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ var chanGraphs = []struct {
7676
// empty graph, the NodeSores function always returns a score of 0.
7777
func TestPrefAttachmentSelectEmptyGraph(t *testing.T) {
7878
t.Parallel()
79-
ctx := context.Background()
79+
ctx := t.Context()
8080
prefAttach := NewPrefAttachment()
8181

8282
// Create a random public key, which we will query to get a score for.
@@ -116,7 +116,7 @@ func TestPrefAttachmentSelectEmptyGraph(t *testing.T) {
116116
// and the funds are appropriately allocated across each peer.
117117
func TestPrefAttachmentSelectTwoVertexes(t *testing.T) {
118118
t.Parallel()
119-
ctx := context.Background()
119+
ctx := t.Context()
120120

121121
prand.Seed(time.Now().Unix())
122122

@@ -203,7 +203,7 @@ func TestPrefAttachmentSelectTwoVertexes(t *testing.T) {
203203
// allocate all funds to each vertex (up to the max channel size).
204204
func TestPrefAttachmentSelectGreedyAllocation(t *testing.T) {
205205
t.Parallel()
206-
ctx := context.Background()
206+
ctx := t.Context()
207207

208208
prand.Seed(time.Now().Unix())
209209

@@ -316,7 +316,7 @@ func TestPrefAttachmentSelectGreedyAllocation(t *testing.T) {
316316
// of zero during scoring.
317317
func TestPrefAttachmentSelectSkipNodes(t *testing.T) {
318318
t.Parallel()
319-
ctx := context.Background()
319+
ctx := t.Context()
320320

321321
prand.Seed(time.Now().Unix())
322322

autopilot/top_centrality_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package autopilot
22

33
import (
4-
"context"
54
"testing"
65

76
"github.com/btcsuite/btcd/btcec/v2"
@@ -59,7 +58,7 @@ func testTopCentrality(t *testing.T, graph testGraph,
5958
// Attempt to get centrality scores and expect
6059
// that the result equals with the expected set.
6160
scores, err := topCentrality.NodeScores(
62-
context.Background(), graph, channels, chanSize, nodes,
61+
t.Context(), graph, channels, chanSize, nodes,
6362
)
6463

6564
require.NoError(t, err)

batch/batch_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package batch
22

33
import (
4-
"context"
54
"database/sql"
65
"encoding/binary"
76
"errors"
@@ -31,7 +30,7 @@ var batchTestIntervals = []time.Duration{
3130
// TestRetry tests the retry logic of the batch scheduler.
3231
func TestRetry(t *testing.T) {
3332
t.Parallel()
34-
ctx := context.Background()
33+
ctx := t.Context()
3534

3635
dbDir := t.TempDir()
3736

@@ -99,7 +98,7 @@ func TestRetry(t *testing.T) {
9998
// and then continue to add a write transaction to the same batch.
10099
func TestReadOnly(t *testing.T) {
101100
t.Parallel()
102-
ctx := context.Background()
101+
ctx := t.Context()
103102

104103
t.Run("bbolt-ReadWrite", func(t *testing.T) {
105104
db, err := walletdb.Create(
@@ -455,7 +454,7 @@ func BenchmarkBoltBatching(b *testing.B) {
455454
// batchTest benches the performance of the batch scheduler configured
456455
// with/without the LazyAdd option and with the given commit interval.
457456
batchTest := func(b *testing.B, lazy bool, interval time.Duration) {
458-
ctx := context.Background()
457+
ctx := b.Context()
459458

460459
db := setUpDB(b)
461460

@@ -549,7 +548,7 @@ func benchmarkSQLBatching(b *testing.B, sqlite bool) {
549548
)
550549
}
551550

552-
ctx := context.Background()
551+
ctx := b.Context()
553552
opts := sqldb.WriteTxOpt()
554553

555554
// writeRecord is a helper that adds a single new invoice to the

chanbackup/backup_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ func TestFetchBackupForChan(t *testing.T) {
121121
}
122122
for i, testCase := range testCases {
123123
_, err := FetchBackupForChan(
124-
context.Background(), testCase.chanPoint, chanSource,
125-
chanSource,
124+
t.Context(), testCase.chanPoint, chanSource, chanSource,
126125
)
127126
switch {
128127
// If this is a valid test case, and we failed, then we'll
@@ -143,7 +142,7 @@ func TestFetchBackupForChan(t *testing.T) {
143142
// channel source for all channels and construct a Single for each channel.
144143
func TestFetchStaticChanBackups(t *testing.T) {
145144
t.Parallel()
146-
ctx := context.Background()
145+
ctx := t.Context()
147146

148147
// First, we'll make the set of channels that we want to seed the
149148
// channel source with. Both channels will be fully populated in the

chanbackup/pubsub_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (m *mockChannelNotifier) SubscribeChans(_ context.Context,
8181
// channel subscription, then the entire sub-swapper will fail to start.
8282
func TestNewSubSwapperSubscribeFail(t *testing.T) {
8383
t.Parallel()
84-
ctx := context.Background()
84+
ctx := t.Context()
8585

8686
keyRing := &lnencrypt.MockKeyRing{}
8787

@@ -159,7 +159,7 @@ func TestSubSwapperIdempotentStartStop(t *testing.T) {
159159

160160
swapper := newMockSwapper(keyRing)
161161
subSwapper, err := NewSubSwapper(
162-
context.Background(), nil, &chanNotifier, keyRing, swapper,
162+
t.Context(), nil, &chanNotifier, keyRing, swapper,
163163
)
164164
require.NoError(t, err, "unable to init subSwapper")
165165

@@ -226,8 +226,7 @@ func TestSubSwapperUpdater(t *testing.T) {
226226
// With our channel set created, we'll make a fresh sub swapper
227227
// instance to begin our test.
228228
subSwapper, err := NewSubSwapper(
229-
context.Background(), initialChanSet, chanNotifier, keyRing,
230-
swapper,
229+
t.Context(), initialChanSet, chanNotifier, keyRing, swapper,
231230
)
232231
require.NoError(t, err, "unable to make swapper")
233232
if err := subSwapper.Start(); err != nil {

channeldb/addr_source_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var (
2020
// deduplicates the results of a set of AddrSource implementations.
2121
func TestMultiAddrSource(t *testing.T) {
2222
t.Parallel()
23-
ctx := context.Background()
23+
ctx := t.Context()
2424

2525
var pk1 = newTestPubKey(t)
2626

channeldb/db_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package channeldb
22

33
import (
4-
"context"
54
"image/color"
65
"math"
76
"math/rand"
@@ -181,7 +180,7 @@ func TestFetchClosedChannelForID(t *testing.T) {
181180
// channel db and graph db.
182181
func TestMultiSourceAddrsForNode(t *testing.T) {
183182
t.Parallel()
184-
ctx := context.Background()
183+
ctx := t.Context()
185184

186185
fullDB, err := MakeTestDB(t)
187186
require.NoError(t, err, "unable to make test database")

0 commit comments

Comments
 (0)