From 28aa092ac2f4f8face0bdcf95c5bdc4d7ef1c3ea Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 29 Jan 2017 17:16:49 -0800 Subject: [PATCH] test: eliminate sleep by tightly polling for existence of node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit elminates a sleep in the testHtlcErrorPropagation test by instead polling for the existence of our target in a tight loop. This is a small patch over until we get a “topology client” within the ChannelRouter. This method is robust and can be applied in future tests until we get the notification client into the ChannelRouter. --- lnd_test.go | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/lnd_test.go b/lnd_test.go index 2597718e..fce2762f 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -402,13 +402,14 @@ func testChannelForceClosure(net *networkHarness, t *harnessTest) { var sweepingTXID *chainhash.Hash var mempool []*chainhash.Hash mempoolTimeout := time.After(3 * time.Second) - checkMempoolTick := time.Tick(100 * time.Millisecond) + checkMempoolTick := time.NewTicker(100 * time.Millisecond) + defer checkMempoolTick.Stop() mempoolPoll: for { select { case <-mempoolTimeout: t.Fatalf("sweep tx not found in mempool") - case <-checkMempoolTick: + case <-checkMempoolTick.C: mempool, err = net.Miner.Node.GetRawMempool() if err != nil { t.Fatalf("unable to fetch node's mempool: %v", err) @@ -1477,9 +1478,31 @@ func testHtlcErrorPropagation(net *networkHarness, t *harnessTest) { chanPointBob := openChannelAndAssert(t, net, ctxt, net.Bob, carol, chanAmt, 0) - // TODO(roasbeef): remove sleep once topology notification hooks are - // in. - time.Sleep(time.Second * 1) + // Ensure that Alice has Carol in her routing table before proceeding. + nodeInfoReq := &lnrpc.NodeInfoRequest{ + PubKey: carol.PubKeyStr, + } + checkTableTimeout := time.After(time.Second * 10) + checkTableTicker := time.NewTicker(100 * time.Millisecond) + defer checkTableTicker.Stop() + +out: + for { + select { + case <-checkTableTicker.C: + _, err := net.Alice.GetNodeInfo(ctxb, nodeInfoReq) + if err != nil && strings.Contains(err.Error(), + "unable to find") { + + continue + } + + break out + case <-checkTableTimeout: + t.Fatalf("carol's node announcement didn't propagate within " + + "the timeout period") + } + } // With the channels, open we can now start to test our multi-hop error // scenarios. First, we'll generate an invoice from carol that we'll @@ -1508,7 +1531,6 @@ func testHtlcErrorPropagation(net *networkHarness, t *harnessTest) { Dest: carol.PubKey[:], Amt: payAmt, } - time.Sleep(time.Millisecond * 500) if err := alicePayStream.Send(sendReq); err != nil { t.Fatalf("unable to send payment: %v", err) }