Skip to content

Commit 2905e7b

Browse files
committed
lntest+itest: kill node and wait its process
Fix a flake found in `testRPCMiddlewareInterceptor` when running in macOS.
1 parent 90bca10 commit 2905e7b

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

itest/lnd_rpc_middleware_interceptor_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,13 @@ func testRPCMiddlewareInterceptor(ht *lntest.HarnessTest) {
153153
// And finally make sure mandatory middleware is always checked for any
154154
// RPC request.
155155
ht.Run("mandatory middleware", func(tt *testing.T) {
156-
st := ht.Subtest(tt)
157-
middlewareMandatoryTest(st, alice)
156+
middlewareMandatoryTest(ht, alice)
158157
})
158+
159+
// We now shut down the node manually to prevent the test from failing
160+
// because we can't call the stop RPC if we unregister the middleware
161+
// in the defer statement above.
162+
ht.KillNode(alice)
159163
}
160164

161165
// middlewareRegistrationRestrictionTests tests all restrictions that apply to
@@ -593,11 +597,6 @@ func middlewareMandatoryTest(ht *lntest.HarnessTest, node *node.HarnessNode) {
593597
time.Sleep(500 * time.Millisecond)
594598
node.RPC.ListChannels(&lnrpc.ListChannelsRequest{})
595599
node.RPC.SubscribeInvoices(&lnrpc.InvoiceSubscription{})
596-
597-
// We now shut down the node manually to prevent the test from failing
598-
// because we can't call the stop RPC if we unregister the middleware
599-
// in the defer statement above.
600-
ht.KillNode(node)
601600
}
602601

603602
// assertInterceptedType makes sure that the intercept message sent by the RPC

lntest/harness.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,9 +841,10 @@ func (h *HarnessTest) NewNodeRemoteSigner(name string, extraArgs []string,
841841
return hn
842842
}
843843

844-
// KillNode kills the node (but won't wait for the node process to stop).
844+
// KillNode kills the node and waits for the node process to stop.
845845
func (h *HarnessTest) KillNode(hn *node.HarnessNode) {
846-
require.NoErrorf(h, hn.Kill(), "%s: kill got error", hn.Name())
846+
h.Logf("Manually killing the node %s", hn.Name())
847+
require.NoErrorf(h, hn.KillAndWait(), "%s: kill got error", hn.Name())
847848
delete(h.manager.activeNodes, hn.Cfg.NodeID)
848849
}
849850

lntest/node/harness_node.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,18 @@ func (hn *HarnessNode) Kill() error {
796796
return hn.cmd.Process.Kill()
797797
}
798798

799+
// KillAndWait kills the lnd process and waits for it to finish.
800+
func (hn *HarnessNode) KillAndWait() error {
801+
err := hn.cmd.Process.Kill()
802+
if err != nil {
803+
return err
804+
}
805+
806+
_, err = hn.cmd.Process.Wait()
807+
808+
return err
809+
}
810+
799811
// printErrf prints an error to the console.
800812
func (hn *HarnessNode) printErrf(format string, a ...interface{}) {
801813
fmt.Printf("itest error from [%s:%s]: %s\n", //nolint:forbidigo

0 commit comments

Comments
 (0)