lntest+itest: kill node and wait its process
Fix a flake found in `testRPCMiddlewareInterceptor` when running in macOS.
This commit is contained in:
3 files changed
+21
-9
No files matched your search
@@ -153,9 +153,13 @@ func testRPCMiddlewareInterceptor(ht *lntest.HarnessTest) {
|
|||||||
// And finally make sure mandatory middleware is always checked for any
|
// And finally make sure mandatory middleware is always checked for any
|
||||||
// RPC request.
|
// RPC request.
|
||||||
ht.Run("mandatory middleware", func(tt *testing.T) {
|
ht.Run("mandatory middleware", func(tt *testing.T) {
|
||||||
st := ht.Subtest(tt)
|
middlewareMandatoryTest(ht, alice)
|
||||||
middlewareMandatoryTest(st, alice)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// We now shut down the node manually to prevent the test from failing
|
||||||
|
// because we can't call the stop RPC if we unregister the middleware
|
||||||
|
// in the defer statement above.
|
||||||
|
ht.KillNode(alice)
|
||||||
}
|
}
|
||||||
|
|
||||||
// middlewareRegistrationRestrictionTests tests all restrictions that apply to
|
// middlewareRegistrationRestrictionTests tests all restrictions that apply to
|
||||||
@@ -593,11 +597,6 @@ func middlewareMandatoryTest(ht *lntest.HarnessTest, node *node.HarnessNode) {
|
|||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
node.RPC.ListChannels(&lnrpc.ListChannelsRequest{})
|
node.RPC.ListChannels(&lnrpc.ListChannelsRequest{})
|
||||||
node.RPC.SubscribeInvoices(&lnrpc.InvoiceSubscription{})
|
node.RPC.SubscribeInvoices(&lnrpc.InvoiceSubscription{})
|
||||||
|
|
||||||
// We now shut down the node manually to prevent the test from failing
|
|
||||||
// because we can't call the stop RPC if we unregister the middleware
|
|
||||||
// in the defer statement above.
|
|
||||||
ht.KillNode(node)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// assertInterceptedType makes sure that the intercept message sent by the RPC
|
// assertInterceptedType makes sure that the intercept message sent by the RPC
|
||||||
|
|||||||
+3
-2
@@ -841,9 +841,10 @@ func (h *HarnessTest) NewNodeRemoteSigner(name string, extraArgs []string,
|
|||||||
return hn
|
return hn
|
||||||
}
|
}
|
||||||
|
|
||||||
// KillNode kills the node (but won't wait for the node process to stop).
|
// KillNode kills the node and waits for the node process to stop.
|
||||||
func (h *HarnessTest) KillNode(hn *node.HarnessNode) {
|
func (h *HarnessTest) KillNode(hn *node.HarnessNode) {
|
||||||
require.NoErrorf(h, hn.Kill(), "%s: kill got error", hn.Name())
|
h.Logf("Manually killing the node %s", hn.Name())
|
||||||
|
require.NoErrorf(h, hn.KillAndWait(), "%s: kill got error", hn.Name())
|
||||||
delete(h.manager.activeNodes, hn.Cfg.NodeID)
|
delete(h.manager.activeNodes, hn.Cfg.NodeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -796,6 +796,18 @@ func (hn *HarnessNode) Kill() error {
|
|||||||
return hn.cmd.Process.Kill()
|
return hn.cmd.Process.Kill()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KillAndWait kills the lnd process and waits for it to finish.
|
||||||
|
func (hn *HarnessNode) KillAndWait() error {
|
||||||
|
err := hn.cmd.Process.Kill()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = hn.cmd.Process.Wait()
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// printErrf prints an error to the console.
|
// printErrf prints an error to the console.
|
||||||
func (hn *HarnessNode) printErrf(format string, a ...interface{}) {
|
func (hn *HarnessNode) printErrf(format string, a ...interface{}) {
|
||||||
fmt.Printf("itest error from [%s:%s]: %s\n", //nolint:forbidigo
|
fmt.Printf("itest error from [%s:%s]: %s\n", //nolint:forbidigo
|
||||||
|
|||||||
Reference in new issue
Block a user