mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
lntemp+lntest: use t.Cleanup
to register cleanup functions
This commit is contained in:
parent
ab62109865
commit
42eab93ba0
@ -31,8 +31,7 @@ func TestFoo(t *testing.T) {
|
||||
// Create a separate harness test for the testcase to
|
||||
// avoid overwriting the external harness test that is
|
||||
// tied to the parent test.
|
||||
ht, cleanup := harnessTest.Subtest(st)
|
||||
defer cleanup()
|
||||
ht := harnessTest.Subtest(st)
|
||||
|
||||
// Run the test cases.
|
||||
ht.RunTestCase(tc)
|
||||
|
@ -279,7 +279,7 @@ func (h *HarnessTest) resetStandbyNodes(t *testing.T) {
|
||||
// stand by nodes created by the parent test. It will return a cleanup function
|
||||
// which resets all the standby nodes' configs back to its original state and
|
||||
// create snapshots of each nodes' internal state.
|
||||
func (h *HarnessTest) Subtest(t *testing.T) (*HarnessTest, func()) {
|
||||
func (h *HarnessTest) Subtest(t *testing.T) *HarnessTest {
|
||||
st := &HarnessTest{
|
||||
T: t,
|
||||
manager: h.manager,
|
||||
@ -304,7 +304,7 @@ func (h *HarnessTest) Subtest(t *testing.T) (*HarnessTest, func()) {
|
||||
// Record block height.
|
||||
_, startHeight := h.Miner.GetBestBlock()
|
||||
|
||||
cleanup := func() {
|
||||
st.Cleanup(func() {
|
||||
_, endHeight := h.Miner.GetBestBlock()
|
||||
|
||||
st.Logf("finished test: %s, start height=%d, end height=%d, "+
|
||||
@ -350,9 +350,9 @@ func (h *HarnessTest) Subtest(t *testing.T) (*HarnessTest, func()) {
|
||||
// running cleanup again since its internal state has been
|
||||
// cleaned up by its child harness tests.
|
||||
h.cleaned = true
|
||||
}
|
||||
})
|
||||
|
||||
return st, cleanup
|
||||
return st
|
||||
}
|
||||
|
||||
// shutdownNonStandbyNodes will shutdown any non-standby nodes.
|
||||
|
@ -401,8 +401,7 @@ func testChannelBackupRestoreBasic(ht *lntemp.HarnessTest) {
|
||||
for _, testCase := range testCases {
|
||||
tc := testCase
|
||||
success := ht.Run(tc.name, func(t *testing.T) {
|
||||
h, cleanup := ht.Subtest(t)
|
||||
defer cleanup()
|
||||
h := ht.Subtest(t)
|
||||
|
||||
runChanRestoreScenarioBasic(h, tc.restoreMethod)
|
||||
})
|
||||
@ -445,17 +444,15 @@ func testChannelBackupRestoreUnconfirmed(ht *lntemp.HarnessTest) {
|
||||
// Use the channel backup file that contains an unconfirmed channel and
|
||||
// make sure recovery works as well.
|
||||
ht.Run("restore unconfirmed channel file", func(t *testing.T) {
|
||||
st, cleanup := ht.Subtest(t)
|
||||
st := ht.Subtest(t)
|
||||
runChanRestoreScenarioUnConfirmed(st, true)
|
||||
cleanup()
|
||||
})
|
||||
|
||||
// Create a backup using RPC that contains an unconfirmed channel and
|
||||
// make sure recovery works as well.
|
||||
ht.Run("restore unconfirmed channel RPC", func(t *testing.T) {
|
||||
st, cleanup := ht.Subtest(t)
|
||||
st := ht.Subtest(t)
|
||||
runChanRestoreScenarioUnConfirmed(st, false)
|
||||
cleanup()
|
||||
})
|
||||
}
|
||||
|
||||
@ -568,8 +565,7 @@ func testChannelBackupRestoreCommitTypes(ht *lntemp.HarnessTest) {
|
||||
for _, testCase := range testCases {
|
||||
tc := testCase
|
||||
success := ht.Run(tc.name, func(t *testing.T) {
|
||||
h, cleanup := ht.Subtest(t)
|
||||
defer cleanup()
|
||||
h := ht.Subtest(t)
|
||||
|
||||
runChanRestoreScenarioCommitTypes(
|
||||
h, tc.ct, tc.zeroConf,
|
||||
@ -671,17 +667,15 @@ func testChannelBackupRestoreForceClose(ht *lntemp.HarnessTest) {
|
||||
// Restore a channel that was force closed by dave just before going
|
||||
// offline.
|
||||
ht.Run("from backup file anchors", func(t *testing.T) {
|
||||
st, cleanup := ht.Subtest(t)
|
||||
st := ht.Subtest(t)
|
||||
runChanRestoreScenarioForceClose(st, false)
|
||||
cleanup()
|
||||
})
|
||||
|
||||
// Restore a zero-conf anchors channel that was force closed by dave
|
||||
// just before going offline.
|
||||
ht.Run("from backup file anchors w/ zero-conf", func(t *testing.T) {
|
||||
st, cleanup := ht.Subtest(t)
|
||||
st := ht.Subtest(t)
|
||||
runChanRestoreScenarioForceClose(st, true)
|
||||
cleanup()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -127,8 +127,7 @@ test:
|
||||
"carol_commit=%v,dave_commit=%v", cc, dc,
|
||||
)
|
||||
success := ht.Run(testName, func(t *testing.T) {
|
||||
st, cleanup := ht.Subtest(t)
|
||||
defer cleanup()
|
||||
st := ht.Subtest(t)
|
||||
testFunding(st, cc, dc)
|
||||
})
|
||||
|
||||
|
@ -171,8 +171,7 @@ func runMultiHopHtlcClaimTest(ht *lntemp.HarnessTest, tester caseRunner) {
|
||||
}
|
||||
|
||||
s := ht.Run(name, func(t1 *testing.T) {
|
||||
st, cleanup := ht.Subtest(t1)
|
||||
defer cleanup()
|
||||
st := ht.Subtest(t1)
|
||||
|
||||
alice := st.NewNode("Alice", args)
|
||||
bob := st.NewNode("Bob", args)
|
||||
|
@ -94,8 +94,7 @@ func TestLightningNetworkDaemonTemp(t *testing.T) {
|
||||
// Create a separate harness test for the testcase to
|
||||
// avoid overwriting the external harness test that is
|
||||
// tied to the parent test.
|
||||
ht, cleanup := harnessTest.Subtest(t1)
|
||||
defer cleanup()
|
||||
ht := harnessTest.Subtest(t1)
|
||||
|
||||
// TODO(yy): split log files.
|
||||
cleanTestCaseName := strings.ReplaceAll(
|
||||
|
Loading…
Reference in New Issue
Block a user