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
@@ -317,7 +317,7 @@ func TestManager(t *testing.T) {
|
||||
expectedNumUpdates = test.expectedNumUpdates
|
||||
|
||||
failedUpdates, err := manager.UpdatePolicy(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
test.newPolicy,
|
||||
test.createMissingEdge,
|
||||
test.specifiedChanPoints...)
|
||||
|
||||
+13
-13
@@ -184,7 +184,7 @@ func makeTestGraph(t *testing.T, useCache bool) (*graphdb.ChannelGraph,
|
||||
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 {
|
||||
@@ -526,7 +526,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
||||
testChannels []*testChannel, source string,
|
||||
sourceFeatureBits ...lnwire.FeatureBit) (*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
|
||||
@@ -1090,7 +1090,7 @@ func runBasicGraphPathFinding(t *testing.T, useCache bool) {
|
||||
func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstance,
|
||||
test *basicGraphPathFindingTestCase) {
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
aliases := graphInstance.aliasMap
|
||||
expectedHops := test.expectedHops
|
||||
expectedHopCount := len(expectedHops)
|
||||
@@ -1235,7 +1235,7 @@ func runPathFindingWithAdditionalEdges(t *testing.T, useCache bool) {
|
||||
graph, err := parseTestGraph(t, useCache, basicGraphFilePath)
|
||||
require.NoError(t, err, "unable to create graph")
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
sourceNode, err := graph.graph.SourceNode(ctx)
|
||||
require.NoError(t, err, "unable to fetch source node")
|
||||
@@ -1320,7 +1320,7 @@ func runPathFindingWithBlindedPathDuplicateHop(t *testing.T, useCache bool) {
|
||||
graph, err := parseTestGraph(t, useCache, basicGraphFilePath)
|
||||
require.NoError(t, err, "unable to create graph")
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
sourceNode, err := graph.graph.SourceNode(ctx)
|
||||
require.NoError(t, err, "unable to fetch source node")
|
||||
@@ -1807,7 +1807,7 @@ func runPathNotAvailable(t *testing.T, useCache bool) {
|
||||
graph, err := parseTestGraph(t, useCache, basicGraphFilePath)
|
||||
require.NoError(t, err, "unable to create graph")
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
sourceNode, err := graph.graph.SourceNode(ctx)
|
||||
require.NoError(t, err, "unable to fetch source node")
|
||||
@@ -1865,7 +1865,7 @@ func runDestTLVGraphFallback(t *testing.T, useCache bool) {
|
||||
|
||||
ctx := newPathFindingTestContext(t, useCache, testChannels, "roasbeef")
|
||||
|
||||
sourceNode, err := ctx.graph.SourceNode(context.Background())
|
||||
sourceNode, err := ctx.graph.SourceNode(t.Context())
|
||||
require.NoError(t, err, "unable to fetch source node")
|
||||
|
||||
find := func(r *RestrictParams,
|
||||
@@ -2083,7 +2083,7 @@ func runPathInsufficientCapacity(t *testing.T, useCache bool) {
|
||||
graph, err := parseTestGraph(t, useCache, basicGraphFilePath)
|
||||
require.NoError(t, err, "unable to create graph")
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
sourceNode, err := graph.graph.SourceNode(ctx)
|
||||
require.NoError(t, err, "unable to fetch source node")
|
||||
|
||||
@@ -2114,7 +2114,7 @@ func runRouteFailMinHTLC(t *testing.T, useCache bool) {
|
||||
graph, err := parseTestGraph(t, useCache, basicGraphFilePath)
|
||||
require.NoError(t, err, "unable to create graph")
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
sourceNode, err := graph.graph.SourceNode(ctx)
|
||||
require.NoError(t, err, "unable to fetch source node")
|
||||
|
||||
@@ -2179,7 +2179,7 @@ func runRouteFailMaxHTLC(t *testing.T, useCache bool) {
|
||||
midEdge.MessageFlags = 1
|
||||
midEdge.MaxHTLC = payAmt - 1
|
||||
midEdge.LastUpdate = midEdge.LastUpdate.Add(time.Second)
|
||||
err = graph.UpdateEdgePolicy(context.Background(), midEdge)
|
||||
err = graph.UpdateEdgePolicy(t.Context(), midEdge)
|
||||
require.NoError(t, err)
|
||||
|
||||
// We'll now attempt to route through that edge with a payment above
|
||||
@@ -2199,7 +2199,7 @@ func runRouteFailDisabledEdge(t *testing.T, useCache bool) {
|
||||
graph, err := parseTestGraph(t, useCache, basicGraphFilePath)
|
||||
require.NoError(t, err, "unable to create graph")
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
sourceNode, err := graph.graph.SourceNode(ctx)
|
||||
require.NoError(t, err, "unable to fetch source node")
|
||||
|
||||
@@ -2268,7 +2268,7 @@ func runPathSourceEdgesBandwidth(t *testing.T, useCache bool) {
|
||||
graph, err := parseTestGraph(t, useCache, basicGraphFilePath)
|
||||
require.NoError(t, err, "unable to create graph")
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
sourceNode, err := graph.graph.SourceNode(ctx)
|
||||
require.NoError(t, err, "unable to fetch source node")
|
||||
|
||||
@@ -3202,7 +3202,7 @@ func newPathFindingTestContext(t *testing.T, useCache bool,
|
||||
require.NoError(t, err, "unable to create graph")
|
||||
|
||||
sourceNode, err := testGraphInstance.graph.SourceNode(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
)
|
||||
require.NoError(t, err, "unable to fetch source node")
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ func sendPaymentAndAssertSucceeded(t *testing.T,
|
||||
// We now make a call to `resumePayment` and expect it to return the
|
||||
// preimage.
|
||||
go func() {
|
||||
preimage, _, err := p.resumePayment(context.Background())
|
||||
preimage, _, err := p.resumePayment(t.Context())
|
||||
resultChan <- &resumePaymentResult{
|
||||
preimage: preimage,
|
||||
err: err,
|
||||
@@ -294,7 +294,7 @@ func TestCheckTimeoutTimedOut(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
deadline := time.Now().Add(time.Nanosecond)
|
||||
ctx, cancel := context.WithDeadline(context.Background(), deadline)
|
||||
ctx, cancel := context.WithDeadline(t.Context(), deadline)
|
||||
defer cancel()
|
||||
|
||||
p := createTestPaymentLifecycle()
|
||||
@@ -330,7 +330,7 @@ func TestCheckTimeoutTimedOut(t *testing.T) {
|
||||
|
||||
// Make the timeout happens instantly.
|
||||
deadline = time.Now().Add(time.Nanosecond)
|
||||
ctx, cancel = context.WithDeadline(context.Background(), deadline)
|
||||
ctx, cancel = context.WithDeadline(t.Context(), deadline)
|
||||
defer cancel()
|
||||
|
||||
// Sleep one millisecond to make sure it timed out.
|
||||
@@ -349,7 +349,7 @@ func TestCheckTimeoutTimedOut(t *testing.T) {
|
||||
func TestCheckTimeoutOnRouterQuit(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
|
||||
p := createTestPaymentLifecycle()
|
||||
@@ -795,7 +795,7 @@ func TestResumePaymentFailOnFetchPayment(t *testing.T) {
|
||||
m.control.On("FetchPayment", p.identifier).Return(nil, errDummy)
|
||||
|
||||
// Send the payment and assert it failed.
|
||||
sendPaymentAndAssertError(t, context.Background(), p, errDummy)
|
||||
sendPaymentAndAssertError(t, t.Context(), p, errDummy)
|
||||
|
||||
// Expected collectResultAsync to not be called.
|
||||
require.Zero(t, m.collectResultsCount)
|
||||
@@ -831,7 +831,7 @@ func TestResumePaymentFailOnTimeout(t *testing.T) {
|
||||
// 3. make the timeout happens instantly and sleep one millisecond to
|
||||
// make sure it timed out.
|
||||
deadline := time.Now().Add(time.Nanosecond)
|
||||
ctx, cancel := context.WithDeadline(context.Background(), deadline)
|
||||
ctx, cancel := context.WithDeadline(t.Context(), deadline)
|
||||
defer cancel()
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
|
||||
@@ -882,7 +882,7 @@ func TestResumePaymentFailOnTimeoutErr(t *testing.T) {
|
||||
|
||||
// Send the payment and assert it failed when router is shutting down.
|
||||
sendPaymentAndAssertError(
|
||||
t, context.Background(), p, ErrRouterShuttingDown,
|
||||
t, t.Context(), p, ErrRouterShuttingDown,
|
||||
)
|
||||
|
||||
// Expected collectResultAsync to not be called.
|
||||
@@ -900,7 +900,7 @@ func TestResumePaymentFailContextCancel(t *testing.T) {
|
||||
p, m := setupTestPaymentLifecycle(t)
|
||||
|
||||
// Create the cancelable payment context.
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
|
||||
paymentAmt := lnwire.MilliSatoshi(10000)
|
||||
|
||||
@@ -977,7 +977,7 @@ func TestResumePaymentFailOnStepErr(t *testing.T) {
|
||||
m.payment.On("AllowMoreAttempts").Return(false, errDummy).Once()
|
||||
|
||||
// Send the payment and assert it failed.
|
||||
sendPaymentAndAssertError(t, context.Background(), p, errDummy)
|
||||
sendPaymentAndAssertError(t, t.Context(), p, errDummy)
|
||||
|
||||
// Expected collectResultAsync to not be called.
|
||||
require.Zero(t, m.collectResultsCount)
|
||||
@@ -1021,7 +1021,7 @@ func TestResumePaymentFailOnRequestRouteErr(t *testing.T) {
|
||||
).Return(nil, errDummy).Once()
|
||||
|
||||
// Send the payment and assert it failed.
|
||||
sendPaymentAndAssertError(t, context.Background(), p, errDummy)
|
||||
sendPaymentAndAssertError(t, t.Context(), p, errDummy)
|
||||
|
||||
// Expected collectResultAsync to not be called.
|
||||
require.Zero(t, m.collectResultsCount)
|
||||
@@ -1081,7 +1081,7 @@ func TestResumePaymentFailOnRegisterAttemptErr(t *testing.T) {
|
||||
).Return(nil, errDummy).Once()
|
||||
|
||||
// Send the payment and assert it failed.
|
||||
sendPaymentAndAssertError(t, context.Background(), p, errDummy)
|
||||
sendPaymentAndAssertError(t, t.Context(), p, errDummy)
|
||||
|
||||
// Expected collectResultAsync to not be called.
|
||||
require.Zero(t, m.collectResultsCount)
|
||||
@@ -1173,7 +1173,7 @@ func TestResumePaymentFailOnSendAttemptErr(t *testing.T) {
|
||||
).Return(nil, errDummy).Once()
|
||||
|
||||
// Send the payment and assert it failed.
|
||||
sendPaymentAndAssertError(t, context.Background(), p, errDummy)
|
||||
sendPaymentAndAssertError(t, t.Context(), p, errDummy)
|
||||
|
||||
// Expected collectResultAsync to not be called.
|
||||
require.Zero(t, m.collectResultsCount)
|
||||
|
||||
@@ -132,7 +132,7 @@ func createTestCtxFromGraphInstanceAssumeValid(t *testing.T,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
sourceNode, err := graphInstance.graph.SourceNode(context.Background())
|
||||
sourceNode, err := graphInstance.graph.SourceNode(t.Context())
|
||||
require.NoError(t, err)
|
||||
sessionSource := &SessionSource{
|
||||
GraphSessionFactory: graphInstance.graph,
|
||||
@@ -1202,7 +1202,7 @@ func TestFindPathFeeWeighting(t *testing.T) {
|
||||
var preImage [32]byte
|
||||
copy(preImage[:], bytes.Repeat([]byte{9}, 32))
|
||||
|
||||
sourceNode, err := ctx.graph.SourceNode(context.Background())
|
||||
sourceNode, err := ctx.graph.SourceNode(t.Context())
|
||||
require.NoError(t, err, "unable to fetch source node")
|
||||
|
||||
amt := lnwire.MilliSatoshi(100)
|
||||
@@ -2706,7 +2706,7 @@ func TestNewRouteRequest(t *testing.T) {
|
||||
// announcements for the channel vertexes to be able to use the channel.
|
||||
func TestAddEdgeUnknownVertexes(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctxb := context.Background()
|
||||
ctxb := t.Context()
|
||||
|
||||
const startingBlockHeight = 101
|
||||
ctx := createTestCtxFromFile(t, startingBlockHeight, basicGraphFilePath)
|
||||
|
||||
Reference in new issue
Block a user