lnd_test: convert assertNumOpenChannelsPending to use waitNoError

This commit is contained in:
Johan T. Halseth 2019-02-06 21:47:40 +01:00
parent 3f3656ae4a
commit 81b2e3502e
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -394,43 +394,36 @@ func numOpenChannelsPending(ctxt context.Context, node *lntest.HarnessNode) (int
func assertNumOpenChannelsPending(ctxt context.Context, t *harnessTest, func assertNumOpenChannelsPending(ctxt context.Context, t *harnessTest,
alice, bob *lntest.HarnessNode, expected int) { alice, bob *lntest.HarnessNode, expected int) {
const nPolls = 10 err := lntest.WaitNoError(func() error {
ticker := time.NewTicker(200 * time.Millisecond)
defer ticker.Stop()
for i := 0; i < nPolls; i++ {
aliceNumChans, err := numOpenChannelsPending(ctxt, alice) aliceNumChans, err := numOpenChannelsPending(ctxt, alice)
if err != nil { if err != nil {
t.Fatalf("error fetching alice's node (%v) pending channels %v", return fmt.Errorf("error fetching alice's node (%v) "+
alice.NodeID, err) "pending channels %v", alice.NodeID, err)
} }
bobNumChans, err := numOpenChannelsPending(ctxt, bob) bobNumChans, err := numOpenChannelsPending(ctxt, bob)
if err != nil { if err != nil {
t.Fatalf("error fetching bob's node (%v) pending channels %v", return fmt.Errorf("error fetching bob's node (%v) "+
bob.NodeID, err) "pending channels %v", bob.NodeID, err)
} }
isLastIteration := i == nPolls-1
aliceStateCorrect := aliceNumChans == expected aliceStateCorrect := aliceNumChans == expected
if !aliceStateCorrect && isLastIteration { if !aliceStateCorrect {
t.Fatalf("number of pending channels for alice incorrect. "+ return fmt.Errorf("number of pending channels for "+
"expected %v, got %v", expected, aliceNumChans) "alice incorrect. expected %v, got %v",
expected, aliceNumChans)
} }
bobStateCorrect := bobNumChans == expected bobStateCorrect := bobNumChans == expected
if !bobStateCorrect && isLastIteration { if !bobStateCorrect {
t.Fatalf("number of pending channels for bob incorrect. "+ return fmt.Errorf("number of pending channels for bob "+
"expected %v, got %v", "incorrect. expected %v, got %v", expected,
expected, bobNumChans) bobNumChans)
} }
if aliceStateCorrect && bobStateCorrect { return nil
return }, 15*time.Second)
} if err != nil {
t.Fatalf(err.Error())
<-ticker.C
} }
} }