channelnotifier+discover+invoices: return error in Stop functions

In order to be consistent with other sub systems an error is now
returned from the Stop functions.
This also allows writing a generic cleanup mechanism to stop all
sub systems in case of a failure.
This commit is contained in:
Roei Erez committed 2021-04-13 13:26:01 +03:00
1 parent c998264578
commit 3223df74e5
10 files changed
+58 -20

No files matched your search

+3 -2
View File
@@ -237,7 +237,7 @@ func (i *InvoiceRegistry) Start() error {
// delete them.
err = i.scanInvoicesOnStart()
if err != nil {
i.Stop()
_ = i.Stop()
return err
}
@@ -245,12 +245,13 @@ func (i *InvoiceRegistry) Start() error {
}
// Stop signals the registry for a graceful shutdown.
func (i *InvoiceRegistry) Stop() {
func (i *InvoiceRegistry) Stop() error {
i.expiryWatcher.Stop()
close(i.quit)
i.wg.Wait()
return nil
}
// invoiceEvent represents a new event that has modified on invoice on disk.
+8 -2
View File
@@ -527,7 +527,11 @@ func TestCancelHoldInvoice(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer registry.Stop()
defer func() {
if err := registry.Stop(); err != nil {
t.Fatalf("failed to stop invoice registry: %v", err)
}
}()
// Add the invoice.
_, err = registry.AddInvoice(testHodlInvoice, testInvoicePaymentHash)
@@ -1005,7 +1009,9 @@ func TestInvoiceExpiryWithRegistry(t *testing.T) {
// Give some time to the watcher to cancel everything.
time.Sleep(500 * time.Millisecond)
registry.Stop()
if err = registry.Stop(); err != nil {
t.Fatalf("failed to stop invoice registry: %v", err)
}
// Create the expected cancellation set before the final check.
expectedCancellations = append(
+3 -1
View File
@@ -215,7 +215,9 @@ func newTestContext(t *testing.T) *testContext {
clock: clock,
t: t,
cleanup: func() {
registry.Stop()
if err = registry.Stop(); err != nil {
t.Fatalf("failed to stop invoice registry: %v", err)
}
cleanup()
},
}