From af660d01521190c01d73e77b9354a7eb0cbf5af0 Mon Sep 17 00:00:00 2001 From: Matheus Degiovani Date: Tue, 2 Jun 2020 13:55:55 -0300 Subject: [PATCH] itest: improve backup check during wt test This replaces an outstanding sleep for a check for a specific state during the test for watchtower use: specifically, that the backup has been sent to the watchtower prior to shutting down Dave. This reduces flakiness in the test that could occur if the Dave shutdown without the backup being comitted to the watchtower, causing the rest of the test to fail. --- lntest/itest/lnd_test.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lntest/itest/lnd_test.go b/lntest/itest/lnd_test.go index 0cf06fd1..254c7c3a 100644 --- a/lntest/itest/lnd_test.go +++ b/lntest/itest/lnd_test.go @@ -9050,6 +9050,29 @@ func testRevokedCloseRetributionAltruistWatchtower(net *lntest.NetworkHarness, davePreSweepBalance := daveBalResp.ConfirmedBalance + // Wait until the backup has been accepted by the watchtower before + // shutting down Dave. + err = wait.NoError(func() error { + ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout) + defer cancel() + bkpStats, err := dave.WatchtowerClient.Stats(ctxt, &wtclientrpc.StatsRequest{}) + if err != nil { + return err + + } + if bkpStats == nil { + return errors.New("no active backup sessions") + } + if bkpStats.NumBackups == 0 { + return errors.New("no backups accepted") + } + + return nil + }, defaultTimeout) + if err != nil { + t.Fatalf("unable to verify backup task completed: %v", err) + } + // Shutdown Dave to simulate going offline for an extended period of // time. Once he's not watching, Carol will try to breach the channel. restart, err := net.SuspendNode(dave) @@ -9078,9 +9101,6 @@ func testRevokedCloseRetributionAltruistWatchtower(net *lntest.NetworkHarness, t.Fatalf("db copy failed: %v", carolChan.NumUpdates) } - // TODO(conner): add hook for backup completion - time.Sleep(3 * time.Second) - // Now force Carol to execute a *force* channel closure by unilaterally // broadcasting his current channel state. This is actually the // commitment transaction of a prior *revoked* state, so he'll soon