mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-20 05:42:05 +02:00
itest+lntest: make sure states are cleaned when tests end
This commit changes how the node's state is updated to make sure the test cleans up the node's state. Also `testLookupHtlcResolution` is fixed with a cleanup.
This commit is contained in:
parent
098bb36114
commit
20e53e85b4
@ -24,6 +24,7 @@ func testLookupHtlcResolution(ht *lntest.HarnessTest) {
|
|||||||
cp := ht.OpenChannel(
|
cp := ht.OpenChannel(
|
||||||
alice, carol, lntest.OpenChannelParams{Amt: chanAmt},
|
alice, carol, lntest.OpenChannelParams{Amt: chanAmt},
|
||||||
)
|
)
|
||||||
|
defer ht.CloseChannel(alice, cp)
|
||||||
|
|
||||||
// Channel should be ready for payments.
|
// Channel should be ready for payments.
|
||||||
const payAmt = 100
|
const payAmt = 100
|
||||||
|
@ -299,9 +299,6 @@ func (h *HarnessTest) resetStandbyNodes(t *testing.T) {
|
|||||||
// config for the coming test. This will also inherit the
|
// config for the coming test. This will also inherit the
|
||||||
// test's running context.
|
// test's running context.
|
||||||
h.RestartNodeWithExtraArgs(hn, hn.Cfg.OriginalExtraArgs)
|
h.RestartNodeWithExtraArgs(hn, hn.Cfg.OriginalExtraArgs)
|
||||||
|
|
||||||
// Update the node's internal state.
|
|
||||||
hn.UpdateState()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,8 +430,19 @@ func (h *HarnessTest) cleanupStandbyNode(hn *node.HarnessNode) {
|
|||||||
// Delete all payments made from this test.
|
// Delete all payments made from this test.
|
||||||
hn.RPC.DeleteAllPayments()
|
hn.RPC.DeleteAllPayments()
|
||||||
|
|
||||||
// Finally, check the node is in a clean state for the following tests.
|
// Check the node's current state with timeout.
|
||||||
h.validateNodeState(hn)
|
//
|
||||||
|
// NOTE: we need to do this in a `wait` because it takes some time for
|
||||||
|
// the node to update its internal state. Once the RPCs are synced we
|
||||||
|
// can then remove this wait.
|
||||||
|
err := wait.NoError(func() error {
|
||||||
|
// Update the node's internal state.
|
||||||
|
hn.UpdateState()
|
||||||
|
|
||||||
|
// Check the node is in a clean state for the following tests.
|
||||||
|
return h.validateNodeState(hn)
|
||||||
|
}, wait.DefaultTimeout)
|
||||||
|
require.NoError(h, err, "timeout checking node's state")
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeConnectionns will remove all connections made on the standby nodes
|
// removeConnectionns will remove all connections made on the standby nodes
|
||||||
@ -752,32 +760,43 @@ func (h *HarnessTest) SetFeeEstimateWithConf(
|
|||||||
|
|
||||||
// validateNodeState checks that the node doesn't have any uncleaned states
|
// validateNodeState checks that the node doesn't have any uncleaned states
|
||||||
// which will affect its following tests.
|
// which will affect its following tests.
|
||||||
func (h *HarnessTest) validateNodeState(hn *node.HarnessNode) {
|
func (h *HarnessTest) validateNodeState(hn *node.HarnessNode) error {
|
||||||
errStr := func(subject string) string {
|
errStr := func(subject string) error {
|
||||||
return fmt.Sprintf("%s: found %s channels, please close "+
|
return fmt.Errorf("%s: found %s channels, please close "+
|
||||||
"them properly", hn.Name(), subject)
|
"them properly", hn.Name(), subject)
|
||||||
}
|
}
|
||||||
// If the node still has open channels, it's most likely that the
|
// If the node still has open channels, it's most likely that the
|
||||||
// current test didn't close it properly.
|
// current test didn't close it properly.
|
||||||
require.Zerof(h, hn.State.OpenChannel.Active, errStr("active"))
|
if hn.State.OpenChannel.Active != 0 {
|
||||||
require.Zerof(h, hn.State.OpenChannel.Public, errStr("public"))
|
return errStr("active")
|
||||||
require.Zerof(h, hn.State.OpenChannel.Private, errStr("private"))
|
}
|
||||||
require.Zerof(h, hn.State.OpenChannel.Pending, errStr("pending open"))
|
if hn.State.OpenChannel.Public != 0 {
|
||||||
|
return errStr("public")
|
||||||
|
}
|
||||||
|
if hn.State.OpenChannel.Private != 0 {
|
||||||
|
return errStr("private")
|
||||||
|
}
|
||||||
|
if hn.State.OpenChannel.Pending != 0 {
|
||||||
|
return errStr("pending open")
|
||||||
|
}
|
||||||
|
|
||||||
// The number of pending force close channels should be zero.
|
// The number of pending force close channels should be zero.
|
||||||
require.Zerof(h, hn.State.CloseChannel.PendingForceClose,
|
if hn.State.CloseChannel.PendingForceClose != 0 {
|
||||||
errStr("pending force"))
|
return errStr("pending force")
|
||||||
|
}
|
||||||
|
|
||||||
// The number of waiting close channels should be zero.
|
// The number of waiting close channels should be zero.
|
||||||
require.Zerof(h, hn.State.CloseChannel.WaitingClose,
|
if hn.State.CloseChannel.WaitingClose != 0 {
|
||||||
errStr("waiting close"))
|
return errStr("waiting close")
|
||||||
|
}
|
||||||
|
|
||||||
// Ths number of payments should be zero.
|
// Ths number of payments should be zero.
|
||||||
// TODO(yy): no need to check since it's deleted in the cleanup? Or
|
if hn.State.Payment.Total != 0 {
|
||||||
// check it in a wait?
|
return fmt.Errorf("%s: found uncleaned payments, please "+
|
||||||
require.Zerof(h, hn.State.Payment.Total, "%s: found "+
|
"delete all of them properly", hn.Name())
|
||||||
"uncleaned payments, please delete all of them properly",
|
}
|
||||||
hn.Name())
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetChanPointFundingTxid takes a channel point and converts it into a chain
|
// GetChanPointFundingTxid takes a channel point and converts it into a chain
|
||||||
|
Loading…
x
Reference in New Issue
Block a user