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
+27
-27
@@ -1024,7 +1024,7 @@ func createTestCtx(t *testing.T, startHeight uint32, isChanPeer bool) (
|
||||
// the router subsystem.
|
||||
func TestProcessAnnouncement(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
timestamp := testTimestamp
|
||||
tCtx, err := createTestCtx(t, 0, false)
|
||||
@@ -1140,7 +1140,7 @@ func TestProcessAnnouncement(t *testing.T) {
|
||||
// propagated to the router subsystem.
|
||||
func TestPrematureAnnouncement(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
timestamp := testTimestamp
|
||||
|
||||
@@ -1176,7 +1176,7 @@ func TestPrematureAnnouncement(t *testing.T) {
|
||||
// properly processes partial and fully announcement signatures message.
|
||||
func TestSignatureAnnouncementLocalFirst(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, proofMatureDelta, false)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -1355,7 +1355,7 @@ func TestSignatureAnnouncementLocalFirst(t *testing.T) {
|
||||
// processes announcement with unknown channel ids.
|
||||
func TestOrphanSignatureAnnouncement(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, proofMatureDelta, false)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -1547,7 +1547,7 @@ func TestOrphanSignatureAnnouncement(t *testing.T) {
|
||||
// assembled.
|
||||
func TestSignatureAnnouncementRetryAtStartup(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, proofMatureDelta, false)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -1783,7 +1783,7 @@ out:
|
||||
// the full proof (ChannelAnnouncement) to the remote peer.
|
||||
func TestSignatureAnnouncementFullProofWhenRemoteProof(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, proofMatureDelta, false)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -2225,7 +2225,7 @@ func TestDeDuplicatedAnnouncements(t *testing.T) {
|
||||
// announcements for nodes who do not intend to publicly advertise themselves.
|
||||
func TestForwardPrivateNodeAnnouncement(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
const (
|
||||
startingHeight = 100
|
||||
@@ -2334,7 +2334,7 @@ func TestForwardPrivateNodeAnnouncement(t *testing.T) {
|
||||
// zombie edges.
|
||||
func TestRejectZombieEdge(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// We'll start by creating our test context with a batch of
|
||||
// announcements.
|
||||
@@ -2436,7 +2436,7 @@ func TestRejectZombieEdge(t *testing.T) {
|
||||
// becomes live by receiving a fresh update.
|
||||
func TestProcessZombieEdgeNowLive(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// We'll start by creating our test context with a batch of
|
||||
// announcements.
|
||||
@@ -2594,7 +2594,7 @@ func TestProcessZombieEdgeNowLive(t *testing.T) {
|
||||
// be reprocessed later, after our ChannelAnnouncement.
|
||||
func TestReceiveRemoteChannelUpdateFirst(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, proofMatureDelta, false)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -2798,7 +2798,7 @@ func TestReceiveRemoteChannelUpdateFirst(t *testing.T) {
|
||||
// currently know of.
|
||||
func TestExtraDataChannelAnnouncementValidation(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, 0, false)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -2835,7 +2835,7 @@ func TestExtraDataChannelAnnouncementValidation(t *testing.T) {
|
||||
// know of.
|
||||
func TestExtraDataChannelUpdateValidation(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
timestamp := testTimestamp
|
||||
tCtx, err := createTestCtx(t, 0, false)
|
||||
@@ -2896,7 +2896,7 @@ func TestExtraDataChannelUpdateValidation(t *testing.T) {
|
||||
// currently know of.
|
||||
func TestExtraDataNodeAnnouncementValidation(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, 0, false)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -2969,7 +2969,7 @@ func assertProcessAnnouncement(t *testing.T, result chan error) {
|
||||
// the retransmit ticker ticks.
|
||||
func TestRetransmit(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, proofMatureDelta, false)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -3079,7 +3079,7 @@ func TestRetransmit(t *testing.T) {
|
||||
// no existing channels in the graph do not get forwarded.
|
||||
func TestNodeAnnouncementNoChannels(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, 0, false)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -3171,7 +3171,7 @@ func TestNodeAnnouncementNoChannels(t *testing.T) {
|
||||
// validate the msg flags and max HTLC field of a ChannelUpdate.
|
||||
func TestOptionalFieldsChannelUpdateValidation(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, 0, false)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -3269,7 +3269,7 @@ func TestOptionalFieldsChannelUpdateValidation(t *testing.T) {
|
||||
// channel is always sent upon the remote party reconnecting.
|
||||
func TestSendChannelUpdateReliably(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// We'll start by creating our test context and a batch of
|
||||
// announcements.
|
||||
@@ -3587,7 +3587,7 @@ func sendRemoteMsg(t *testing.T, ctx *testCtx, msg lnwire.Message,
|
||||
|
||||
select {
|
||||
case err := <-ctx.gossiper.ProcessRemoteAnnouncement(
|
||||
context.Background(), msg, remotePeer,
|
||||
t.Context(), msg, remotePeer,
|
||||
):
|
||||
if err != nil {
|
||||
t.Fatalf("unable to process channel msg: %v", err)
|
||||
@@ -3718,7 +3718,7 @@ out:
|
||||
// policy of all of them.
|
||||
const newTimeLockDelta = 100
|
||||
var edgesToUpdate []EdgeWithInfo
|
||||
err = ctx.router.ForAllOutgoingChannels(context.Background(), func(
|
||||
err = ctx.router.ForAllOutgoingChannels(t.Context(), func(
|
||||
info *models.ChannelEdgeInfo,
|
||||
edge *models.ChannelEdgePolicy) error {
|
||||
|
||||
@@ -3986,7 +3986,7 @@ func (m *SyncManager) markGraphSyncing() {
|
||||
// initial historical sync has completed.
|
||||
func TestBroadcastAnnsAfterGraphSynced(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, 10, false)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -4064,7 +4064,7 @@ func TestBroadcastAnnsAfterGraphSynced(t *testing.T) {
|
||||
// is tested by TestRateLimitChannelUpdates.
|
||||
func TestRateLimitDeDup(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// Create our test harness.
|
||||
const blockHeight = 100
|
||||
@@ -4261,7 +4261,7 @@ func TestRateLimitDeDup(t *testing.T) {
|
||||
// channel updates.
|
||||
func TestRateLimitChannelUpdates(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// Create our test harness.
|
||||
const blockHeight = 100
|
||||
@@ -4416,7 +4416,7 @@ func TestRateLimitChannelUpdates(t *testing.T) {
|
||||
// about our own channels when coming from a remote peer.
|
||||
func TestIgnoreOwnAnnouncement(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, proofMatureDelta, false)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -4563,7 +4563,7 @@ func TestIgnoreOwnAnnouncement(t *testing.T) {
|
||||
// error.
|
||||
func TestRejectCacheChannelAnn(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, proofMatureDelta, false)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -4644,7 +4644,7 @@ func TestFutureMsgCacheEviction(t *testing.T) {
|
||||
// channel announcements are banned properly.
|
||||
func TestChanAnnBanningNonChanPeer(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, 1000, false)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -4739,7 +4739,7 @@ func TestChanAnnBanningNonChanPeer(t *testing.T) {
|
||||
// get disconnected.
|
||||
func TestChanAnnBanningChanPeer(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
tCtx, err := createTestCtx(t, 1000, true)
|
||||
require.NoError(t, err, "can't create context")
|
||||
@@ -4832,7 +4832,7 @@ func assertChanChainRejection(t *testing.T, ctx *testCtx,
|
||||
}
|
||||
|
||||
_, added := ctx.gossiper.handleChanAnnouncement(
|
||||
context.Background(), nMsg, edge,
|
||||
t.Context(), nMsg, edge,
|
||||
)
|
||||
require.False(t, added)
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ func assertMsgsSent(t *testing.T, msgChan chan lnwire.Message,
|
||||
// a peer while taking into account its connection lifecycle works as expected.
|
||||
func TestReliableSenderFlow(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
reliableSender := newTestReliableSender(t)
|
||||
|
||||
@@ -188,7 +188,7 @@ func TestReliableSenderFlow(t *testing.T) {
|
||||
// them as stale.
|
||||
func TestReliableSenderStaleMessages(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
reliableSender := newTestReliableSender(t)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
// backlog at a time using the atomic flag.
|
||||
func TestGossipSyncerSingleBacklogSend(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// Track how many goroutines are actively sending.
|
||||
var (
|
||||
|
||||
+14
-14
@@ -232,7 +232,7 @@ func newTestSyncer(hID lnwire.ShortChannelID,
|
||||
// doesn't have a horizon set, then we won't send any incoming messages to it.
|
||||
func TestGossipSyncerFilterGossipMsgsNoHorizon(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// First, we'll create a GossipSyncer instance with a canned sendToPeer
|
||||
// message to allow us to intercept their potential sends.
|
||||
@@ -278,7 +278,7 @@ func unixStamp(a int64) uint32 {
|
||||
// channel ann that already has a channel update on disk.
|
||||
func TestGossipSyncerFilterGossipMsgsAllInMemory(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// First, we'll create a GossipSyncer instance with a canned sendToPeer
|
||||
// message to allow us to intercept their potential sends.
|
||||
@@ -421,7 +421,7 @@ func TestGossipSyncerFilterGossipMsgsAllInMemory(t *testing.T) {
|
||||
// messages which are within their desired time horizon.
|
||||
func TestGossipSyncerApplyNoHistoricalGossipFilter(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// First, we'll create a GossipSyncer instance with a canned sendToPeer
|
||||
// message to allow us to intercept their potential sends.
|
||||
@@ -482,7 +482,7 @@ func TestGossipSyncerApplyNoHistoricalGossipFilter(t *testing.T) {
|
||||
// within their desired time horizon.
|
||||
func TestGossipSyncerApplyGossipFilter(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// First, we'll create a GossipSyncer instance with a canned sendToPeer
|
||||
// message to allow us to intercept their potential sends.
|
||||
@@ -602,7 +602,7 @@ func TestGossipSyncerApplyGossipFilter(t *testing.T) {
|
||||
// channels and complete=0.
|
||||
func TestGossipSyncerQueryChannelRangeWrongChainHash(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// First, we'll create a GossipSyncer instance with a canned sendToPeer
|
||||
// message to allow us to intercept their potential sends.
|
||||
@@ -655,7 +655,7 @@ func TestGossipSyncerQueryChannelRangeWrongChainHash(t *testing.T) {
|
||||
// complete=0.
|
||||
func TestGossipSyncerReplyShortChanIDsWrongChainHash(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// First, we'll create a GossipSyncer instance with a canned sendToPeer
|
||||
// message to allow us to intercept their potential sends.
|
||||
@@ -705,7 +705,7 @@ func TestGossipSyncerReplyShortChanIDsWrongChainHash(t *testing.T) {
|
||||
// announcements, as well as an ending ReplyShortChanIDsEnd message.
|
||||
func TestGossipSyncerReplyShortChanIDs(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// First, we'll create a GossipSyncer instance with a canned sendToPeer
|
||||
// message to allow us to intercept their potential sends.
|
||||
@@ -811,7 +811,7 @@ func TestGossipSyncerReplyShortChanIDs(t *testing.T) {
|
||||
// the remote peer.
|
||||
func TestGossipSyncerReplyChanRangeQuery(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// We'll use a smaller chunk size so we can easily test all the edge
|
||||
// cases.
|
||||
@@ -983,7 +983,7 @@ func TestGossipSyncerReplyChanRangeQuery(t *testing.T) {
|
||||
// executed with the correct block range.
|
||||
func TestGossipSyncerReplyChanRangeQueryBlockRange(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// First create our test gossip syncer that will handle and
|
||||
// respond to the test queries
|
||||
@@ -1097,7 +1097,7 @@ func TestGossipSyncerReplyChanRangeQueryBlockRange(t *testing.T) {
|
||||
// back a single response that signals completion.
|
||||
func TestGossipSyncerReplyChanRangeQueryNoNewChans(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// We'll now create our test gossip syncer that will shortly respond to
|
||||
// our canned query.
|
||||
@@ -1177,7 +1177,7 @@ func TestGossipSyncerReplyChanRangeQueryNoNewChans(t *testing.T) {
|
||||
// channel ID, we properly generate an correct initial channel range response.
|
||||
func TestGossipSyncerGenChanRangeQuery(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// First, we'll create a GossipSyncer instance with a canned sendToPeer
|
||||
// message to allow us to intercept their potential sends.
|
||||
@@ -1238,7 +1238,7 @@ func TestGossipSyncerProcessChanRangeReply(t *testing.T) {
|
||||
// each reply instead.
|
||||
func testGossipSyncerProcessChanRangeReply(t *testing.T, legacy bool) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
|
||||
// First, we'll create a GossipSyncer instance with a canned sendToPeer
|
||||
// message to allow us to intercept their potential sends.
|
||||
@@ -1499,7 +1499,7 @@ func TestGossipSyncerSynchronizeChanIDs(t *testing.T) {
|
||||
|
||||
for i := 0; i < chunkSize*2; i += 2 {
|
||||
// With our set up complete, we'll request a sync of chan ID's.
|
||||
done := syncer.synchronizeChanIDs(context.Background())
|
||||
done := syncer.synchronizeChanIDs(t.Context())
|
||||
|
||||
// At this point, we shouldn't yet be done as only 2 items
|
||||
// should have been queried for.
|
||||
@@ -1546,7 +1546,7 @@ func TestGossipSyncerSynchronizeChanIDs(t *testing.T) {
|
||||
}
|
||||
|
||||
// If we issue another query, the syncer should tell us that it's done.
|
||||
done := syncer.synchronizeChanIDs(context.Background())
|
||||
done := syncer.synchronizeChanIDs(t.Context())
|
||||
if done {
|
||||
t.Fatalf("syncer should be finished!")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user