From fdf2b9106987c26cab030ed7676b3d1c79884ed6 Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Thu, 5 Mar 2026 13:02:04 +0100 Subject: [PATCH] loopout_test: fix goroutine leak in TestCustomSweepConfTarget Send the batch confirmation after AssertRegisterConf so the batch exits cleanly, and use a cancellable context so the batcher stops before leaktest runs. --- loopout_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/loopout_test.go b/loopout_test.go index fb1622b4..25c9e230 100644 --- a/loopout_test.go +++ b/loopout_test.go @@ -330,7 +330,8 @@ func testCustomSweepConfTarget(t *testing.T) { lnd.ChainParams, batcherStore, sweepStore, ) - tctx := t.Context() + tctx, cancel := context.WithCancel(t.Context()) + defer cancel() go func() { err := batcher.Run(tctx) @@ -484,6 +485,9 @@ func testCustomSweepConfTarget(t *testing.T) { // confirmations. ctx.AssertRegisterConf(true, 3) + // Send the batch confirmation so the batch exits cleanly. + ctx.NotifyConf(sweepTx) + cfg.store.(*loopdb.StoreMock).AssertLoopOutState(loopdb.StateSuccess) status = <-statusChan require.Equal(t, loopdb.StateSuccess, status.State) @@ -567,7 +571,8 @@ func testPreimagePush(t *testing.T) { lnd.ChainParams, batcherStore, sweepStore, ) - tctx := t.Context() + tctx, cancel := context.WithCancel(t.Context()) + defer cancel() go func() { err := batcher.Run(tctx) @@ -577,7 +582,7 @@ func testPreimagePush(t *testing.T) { }() go func() { - err := swap.execute(context.Background(), &executeConfig{ + err := swap.execute(tctx, &executeConfig{ statusChan: statusChan, blockEpochChan: blockEpochChan, timerFactory: timerFactory, @@ -986,7 +991,8 @@ func TestLoopOutMuSig2Sweep(t *testing.T) { lnd.ChainParams, batcherStore, sweepStore, ) - tctx := t.Context() + tctx, cancel := context.WithCancel(t.Context()) + defer cancel() go func() { err := batcher.Run(tctx) @@ -996,7 +1002,7 @@ func TestLoopOutMuSig2Sweep(t *testing.T) { }() go func() { - err := swap.execute(context.Background(), &executeConfig{ + err := swap.execute(tctx, &executeConfig{ statusChan: statusChan, blockEpochChan: blockEpochChan, timerFactory: timerFactory,