test: cancel the daemon panic goroutine after interaction tests

This commit is contained in:
Olaoluwa Osuntokun
2016-11-16 12:42:58 -08:00
parent 8053f841e4
commit 8608ffba15

View File

@@ -7,6 +7,8 @@ import (
"testing" "testing"
"time" "time"
"sync/atomic"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/go-errors/errors" "github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
@@ -16,7 +18,6 @@ import (
"github.com/roasbeef/btcutil" "github.com/roasbeef/btcutil"
"golang.org/x/net/context" "golang.org/x/net/context"
"google.golang.org/grpc" "google.golang.org/grpc"
"sync/atomic"
) )
// harnessTest wraps a regular testing.T providing enhanced error detection // harnessTest wraps a regular testing.T providing enhanced error detection
@@ -51,7 +52,6 @@ func (h *harnessTest) Fatalf(format string, a ...interface{}) {
} }
} }
// RunTestCase executes a harness test-case. Any errors or panics will be // RunTestCase executes a harness test-case. Any errors or panics will be
// represented as fatal. // represented as fatal.
func (h *harnessTest) RunTestCase(testCase *testCase, net *networkHarness) { func (h *harnessTest) RunTestCase(testCase *testCase, net *networkHarness) {
@@ -994,14 +994,21 @@ func TestLightningNetworkDaemon(t *testing.T) {
// fails immediately with a fatal error, as far as fatal is happening // fails immediately with a fatal error, as far as fatal is happening
// inside goroutine main goroutine would not be finished at the same // inside goroutine main goroutine would not be finished at the same
// time as we receive fatal error from lnd process. // time as we receive fatal error from lnd process.
testsFin := make(chan struct{})
go func() { go func() {
err := <-lndHarness.ProcessErrors() select {
case err := <-lndHarness.ProcessErrors():
ht.Fatalf("lnd finished with error (stderr): "+ ht.Fatalf("lnd finished with error (stderr): "+
"\n%v", err) "\n%v", err)
case <-testsFin:
return
}
}() }()
t.Logf("Running %v integration tests", len(testsCases)) t.Logf("Running %v integration tests", len(testsCases))
for _, testCase := range testsCases { for _, testCase := range testsCases {
ht.RunTestCase(testCase, lndHarness) ht.RunTestCase(testCase, lndHarness)
} }
close(testsFin)
} }