Skip to content

Commit 1b25d8a

Browse files
stariushieblmi
authored andcommitted
sweepbatcher: assert close-during-add run exit
TestSweepBatcherCloseDuringAdding previously started Batcher.Run in a detached goroutine and called test assertions from that goroutine. The test only waited for the add/cancel workers, so a Run-side shutdown error could be missed or reported unreliably. Route the Run result through a channel and wait for it in the main test goroutine. While waiting, keep draining spend registrations so shutdown cannot deadlock on mock notifier traffic. This makes the existing shutdown-race test cover both sides of the race: AddSweep callers may exit with cancellation, and Batcher.Run must also terminate with an expected shutdown error.
1 parent 707fef3 commit 1b25d8a

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

sweepbatcher/sweep_batcher_test.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4208,9 +4208,9 @@ func testSweepBatcherCloseDuringAdding(t *testing.T, store testStore,
42084208
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
42094209
testMuSig2SignSweep, testVerifySchnorrSig, lnd.ChainParams,
42104210
batcherStore, sweepStore)
4211+
runErrChan := make(chan error, 1)
42114212
go func() {
4212-
err := batcher.Run(ctx)
4213-
checkBatcherError(t, err)
4213+
runErrChan <- batcher.Run(ctx)
42144214
}()
42154215

42164216
// Add many swaps.
@@ -4276,23 +4276,28 @@ func testSweepBatcherCloseDuringAdding(t *testing.T, store testStore,
42764276
})
42774277

42784278
// We don't know how many spend notification registrations will be
4279-
// issued, so accept them while waiting for two goroutines to stop.
4280-
quit := make(chan struct{})
4281-
registrationChan := make(chan struct{})
4279+
// issued, so accept them while waiting for all goroutines to stop.
4280+
addDone := make(chan struct{})
42824281
go func() {
4283-
defer close(registrationChan)
4284-
for {
4285-
select {
4286-
case <-lnd.RegisterSpendChannel:
4287-
case <-quit:
4288-
return
4289-
}
4290-
}
4282+
defer close(addDone)
4283+
wg.Wait()
42914284
}()
42924285

4293-
wg.Wait()
4294-
close(quit)
4295-
<-registrationChan
4286+
for addDone != nil || runErrChan != nil {
4287+
select {
4288+
case <-lnd.RegisterSpendChannel:
4289+
4290+
case <-addDone:
4291+
addDone = nil
4292+
4293+
case err := <-runErrChan:
4294+
checkBatcherError(t, err)
4295+
runErrChan = nil
4296+
4297+
case <-time.After(test.Timeout):
4298+
t.Fatalf("expected batcher close during adding to finish")
4299+
}
4300+
}
42964301
}
42974302

42984303
// testSweepBatcherHandleSweepRace reproduces a race between AddSweep and the

0 commit comments

Comments
 (0)