From 809d2383642c0751c7abc8fc224f9090a0c7745d Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 8 Dec 2020 16:27:03 +0100 Subject: [PATCH] itest: wait for server to start when restoring To avoid running into the "server is still starting" error when trying to close a channel, we first wait for the error to disappear before we try closing the actual channel. --- lntest/itest/lnd_channel_backup_test.go | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lntest/itest/lnd_channel_backup_test.go b/lntest/itest/lnd_channel_backup_test.go index 5c650ff4..5b6f2fcd 100644 --- a/lntest/itest/lnd_channel_backup_test.go +++ b/lntest/itest/lnd_channel_backup_test.go @@ -987,6 +987,33 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness, ) require.NoError(t.t, err) + // We now need to make sure the server is fully started before we can + // actually close the channel. This is the first check in CloseChannel + // so we can try with a nil channel point until we get the correct error + // to find out if Dave is fully started. + err = wait.Predicate(func() bool { + const expectedErr = "must specify channel point" + ctxc, cancel := context.WithCancel(ctxt) + defer cancel() + + resp, err := dave.CloseChannel( + ctxc, &lnrpc.CloseChannelRequest{}, + ) + if err != nil { + return false + } + + defer func() { _ = resp.CloseSend() }() + + _, err = resp.Recv() + if err != nil && strings.Contains(err.Error(), expectedErr) { + return true + } + + return false + }, defaultTimeout) + require.NoError(t.t, err) + // We also want to make sure we cannot force close in this state. That // would get the state machine in a weird state. chanPointParts := strings.Split(