mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
loopd: test error reporting logic
This commit is contained in:
parent
360af61005
commit
d1c4a7da8a
2 changed files with 61 additions and 4 deletions
|
|
@ -47,6 +47,13 @@ var (
|
|||
errOnlyStartOnce = fmt.Errorf("daemon can only be started once")
|
||||
)
|
||||
|
||||
// shouldReportManagerErr determines whether a manager error should be forwarded
|
||||
// to the internal error channel. Context cancellations are treated as
|
||||
// non-fatal.
|
||||
func shouldReportManagerErr(err error) bool {
|
||||
return err != nil && !errors.Is(err, context.Canceled)
|
||||
}
|
||||
|
||||
// ListenerCfg holds closures used to retrieve listeners for the gRPC services.
|
||||
type ListenerCfg struct {
|
||||
// grpcListener returns a TLS listener to use for the gRPC server, based
|
||||
|
|
@ -892,7 +899,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
|||
defer infof("Static address manager stopped")
|
||||
|
||||
err := staticAddressManager.Run(d.mainCtx, initChan)
|
||||
if err != nil && !errors.Is(err, context.Canceled) {
|
||||
if shouldReportManagerErr(err) {
|
||||
d.internalErrChan <- err
|
||||
}
|
||||
}()
|
||||
|
|
@ -924,7 +931,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
|||
defer infof("Static address deposit manager stopped")
|
||||
|
||||
err := depositManager.Run(d.mainCtx, initChan)
|
||||
if err != nil && !errors.Is(err, context.Canceled) {
|
||||
if shouldReportManagerErr(err) {
|
||||
d.internalErrChan <- err
|
||||
}
|
||||
}()
|
||||
|
|
@ -956,7 +963,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
|||
defer infof("Static address withdrawal manager stopped")
|
||||
|
||||
err := withdrawalManager.Run(d.mainCtx, initChan)
|
||||
if err != nil && !errors.Is(err, context.Canceled) {
|
||||
if shouldReportManagerErr(err) {
|
||||
d.internalErrChan <- err
|
||||
}
|
||||
}()
|
||||
|
|
@ -992,7 +999,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
|||
infof("Starting static address loop-in manager...")
|
||||
defer infof("Static address loop-in manager stopped")
|
||||
err := staticLoopInManager.Run(d.mainCtx, initChan)
|
||||
if err != nil && !errors.Is(err, context.Canceled) {
|
||||
if shouldReportManagerErr(err) {
|
||||
d.internalErrChan <- err
|
||||
}
|
||||
}()
|
||||
|
|
|
|||
50
loopd/daemon_test.go
Normal file
50
loopd/daemon_test.go
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package loopd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestShouldReportManagerErr verifies that context cancellations are treated as
|
||||
// non-fatal while other errors are reported.
|
||||
func TestShouldReportManagerErr(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
err error
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "nil error",
|
||||
err: nil,
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "context canceled",
|
||||
err: context.Canceled,
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "wrapped context canceled",
|
||||
err: fmt.Errorf("wrap: %w", context.Canceled),
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "other error",
|
||||
err: errors.New("boom"),
|
||||
expected: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := shouldReportManagerErr(tt.err)
|
||||
require.Equal(t, tt.expected, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue