lnd_test: add lndHarness to harnessTest, dump goroutines on Fatalf

Co-authored-by: taketa <853211b@gmail.com>
This commit is contained in:
Johan T. Halseth 2019-04-15 16:19:47 +02:00
parent 314ba7db03
commit 8d5430dae3
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

View File

@ -73,12 +73,16 @@ type harnessTest struct {
// testCase is populated during test execution and represents the // testCase is populated during test execution and represents the
// current test case. // current test case.
testCase *testCase testCase *testCase
// lndHarness is a reference to the current network harness. Will be
// nil if not yet set up.
lndHarness *lntest.NetworkHarness
} }
// newHarnessTest creates a new instance of a harnessTest from a regular // newHarnessTest creates a new instance of a harnessTest from a regular
// testing.T instance. // testing.T instance.
func newHarnessTest(t *testing.T) *harnessTest { func newHarnessTest(t *testing.T, net *lntest.NetworkHarness) *harnessTest {
return &harnessTest{t, nil} return &harnessTest{t, nil, net}
} }
// Skipf calls the underlying testing.T's Skip method, causing the current test // Skipf calls the underlying testing.T's Skip method, causing the current test
@ -91,6 +95,10 @@ func (h *harnessTest) Skipf(format string, args ...interface{}) {
// integration tests should mark test failures solely with this method due to // integration tests should mark test failures solely with this method due to
// the error stack traces it produces. // the error stack traces it produces.
func (h *harnessTest) Fatalf(format string, a ...interface{}) { func (h *harnessTest) Fatalf(format string, a ...interface{}) {
if h.lndHarness != nil {
h.lndHarness.SaveProfilesPages()
}
stacktrace := errors.Wrap(fmt.Sprintf(format, a...), 1).ErrorStack() stacktrace := errors.Wrap(fmt.Sprintf(format, a...), 1).ErrorStack()
if h.testCase != nil { if h.testCase != nil {
@ -103,8 +111,7 @@ 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, func (h *harnessTest) RunTestCase(testCase *testCase) {
net *lntest.NetworkHarness) {
h.testCase = testCase h.testCase = testCase
defer func() { defer func() {
@ -119,7 +126,7 @@ func (h *harnessTest) RunTestCase(testCase *testCase,
} }
}() }()
testCase.test(net, h) testCase.test(h.lndHarness, h)
return return
} }
@ -13513,7 +13520,7 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) {
for _, testCase := range testCases { for _, testCase := range testCases {
success := t.t.Run(testCase.name, func(t *testing.T) { success := t.t.Run(testCase.name, func(t *testing.T) {
h := newHarnessTest(t) h := newHarnessTest(t, net)
testChanRestoreScenario(h, net, &testCase, password) testChanRestoreScenario(h, net, &testCase, password)
}) })
if !success { if !success {
@ -14267,7 +14274,7 @@ var testsCases = []*testCase{
// TestLightningNetworkDaemon performs a series of integration tests amongst a // TestLightningNetworkDaemon performs a series of integration tests amongst a
// programmatically driven network of lnd nodes. // programmatically driven network of lnd nodes.
func TestLightningNetworkDaemon(t *testing.T) { func TestLightningNetworkDaemon(t *testing.T) {
ht := newHarnessTest(t) ht := newHarnessTest(t, nil)
// Declare the network harness here to gain access to its // Declare the network harness here to gain access to its
// 'OnTxAccepted' call back. // 'OnTxAccepted' call back.
@ -14391,8 +14398,8 @@ func TestLightningNetworkDaemon(t *testing.T) {
} }
success := t.Run(testCase.name, func(t1 *testing.T) { success := t.Run(testCase.name, func(t1 *testing.T) {
ht := newHarnessTest(t1) ht := newHarnessTest(t1, lndHarness)
ht.RunTestCase(testCase, lndHarness) ht.RunTestCase(testCase)
}) })
// Stop at the first failure. Mimic behavior of original test // Stop at the first failure. Mimic behavior of original test