test: don't panic within lightningNetworkWatcher if lnd is shutting down

This commit fixes an issue in the newly added integration tests level
topology notifications that caused tests to erronosely panic when the
daemon was detected to be shutting down. This issue was notified by
AndrewSamokhvalov.

We fix this issue by checking if the error is a shutdown error, and
exiting early if so. Additionally we add a fail-fast case if the quit
channel for the node has already been closed.
This commit is contained in:
Olaoluwa Osuntokun 2017-03-16 12:15:37 -07:00
parent 0db384fd6b
commit 57a7d58ef9
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -12,6 +12,7 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"time"
@ -339,6 +340,12 @@ type chanWatchRequest struct {
func (l *lightningNode) lightningNetworkWatcher() {
defer l.wg.Done()
// If the channel router is shutting down, then we won't consider it as
// a real error. This just indicates the daemon itself is quitting.
isShutdownError := func(err error) bool {
return strings.Contains(err.Error(), "shutting down")
}
graphUpdates := make(chan *lnrpc.GraphTopologyUpdate)
go func() {
ctxb := context.Background()
@ -357,6 +364,20 @@ func (l *lightningNode) lightningNetworkWatcher() {
if err == io.EOF {
return
} else if err != nil {
// If the node has been signalled to quit, then
// we'll exit early.
select {
case <-l.quit:
return
default:
}
// Otherwise, if the node is shutting down on
// it's own, then we'll also bail out early.
if isShutdownError(err) {
return
}
// Similar to the case above, we also panic
// here (and end the tests) as these
// notifications are critical to the success of