test: eliminate sleep by tightly polling for existence of node

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.
This commit is contained in:
Olaoluwa Osuntokun 2017-01-29 17:16:49 -08:00
parent 51e38d7544
commit 28aa092ac2
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -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)
}