From 81b2e3502e50e97989028d902374ca32e21a0925 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 6 Feb 2019 21:47:40 +0100 Subject: [PATCH] lnd_test: convert assertNumOpenChannelsPending to use waitNoError --- lnd_test.go | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/lnd_test.go b/lnd_test.go index ee0becfc..e018c0b6 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -394,43 +394,36 @@ func numOpenChannelsPending(ctxt context.Context, node *lntest.HarnessNode) (int func assertNumOpenChannelsPending(ctxt context.Context, t *harnessTest, alice, bob *lntest.HarnessNode, expected int) { - const nPolls = 10 - - ticker := time.NewTicker(200 * time.Millisecond) - defer ticker.Stop() - - for i := 0; i < nPolls; i++ { + err := lntest.WaitNoError(func() error { aliceNumChans, err := numOpenChannelsPending(ctxt, alice) if err != nil { - t.Fatalf("error fetching alice's node (%v) pending channels %v", - alice.NodeID, err) + return fmt.Errorf("error fetching alice's node (%v) "+ + "pending channels %v", alice.NodeID, err) } bobNumChans, err := numOpenChannelsPending(ctxt, bob) if err != nil { - t.Fatalf("error fetching bob's node (%v) pending channels %v", - bob.NodeID, err) + return fmt.Errorf("error fetching bob's node (%v) "+ + "pending channels %v", bob.NodeID, err) } - isLastIteration := i == nPolls-1 - aliceStateCorrect := aliceNumChans == expected - if !aliceStateCorrect && isLastIteration { - t.Fatalf("number of pending channels for alice incorrect. "+ - "expected %v, got %v", expected, aliceNumChans) + if !aliceStateCorrect { + return fmt.Errorf("number of pending channels for "+ + "alice incorrect. expected %v, got %v", + expected, aliceNumChans) } bobStateCorrect := bobNumChans == expected - if !bobStateCorrect && isLastIteration { - t.Fatalf("number of pending channels for bob incorrect. "+ - "expected %v, got %v", - expected, bobNumChans) + if !bobStateCorrect { + return fmt.Errorf("number of pending channels for bob "+ + "incorrect. expected %v, got %v", expected, + bobNumChans) } - if aliceStateCorrect && bobStateCorrect { - return - } - - <-ticker.C + return nil + }, 15*time.Second) + if err != nil { + t.Fatalf(err.Error()) } }