test: make assertNumOpenChannelsPending poll every 200ms

In this commit, we modify the assertNumOpenChannelsPending to poll
every 200ms rather than just a single attempt. The goal of this commit
is to reduce the number of flakes on travis caused by slow instances.
This commit is contained in:
Olaoluwa Osuntokun committed 2017-11-02 15:48:06 -07:00
1 parent 34a165dd12
commit 8a9cf9af16
1 file changed
+22 -2
+22 -2
View File
@@ -245,6 +245,13 @@ func numOpenChannelsPending(ctxt context.Context, node *lightningNode) (int, err
// number of pending channels between them. // number of pending channels between them.
func assertNumOpenChannelsPending(ctxt context.Context, t *harnessTest, func assertNumOpenChannelsPending(ctxt context.Context, t *harnessTest,
alice, bob *lightningNode, expected int) { alice, bob *lightningNode, expected int) {
const nPolls = 10
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", t.Fatalf("error fetching alice's node (%v) pending channels %v",
@@ -255,15 +262,28 @@ func assertNumOpenChannelsPending(ctxt context.Context, t *harnessTest,
t.Fatalf("error fetching bob's node (%v) pending channels %v", t.Fatalf("error fetching bob's node (%v) pending channels %v",
bob.nodeID, err) bob.nodeID, err)
} }
if aliceNumChans != expected {
isLastIteration := i == nPolls-1
aliceStateCorrect := aliceNumChans == expected
if !aliceStateCorrect && isLastIteration {
t.Fatalf("number of pending channels for alice incorrect. "+ t.Fatalf("number of pending channels for alice incorrect. "+
"expected %v, got %v", expected, aliceNumChans) "expected %v, got %v", expected, aliceNumChans)
} }
if bobNumChans != expected {
bobStateCorrect := bobNumChans == expected
if !bobStateCorrect && isLastIteration {
t.Fatalf("number of pending channels for bob incorrect. "+ t.Fatalf("number of pending channels for bob incorrect. "+
"expected %v, got %v", "expected %v, got %v",
expected, bobNumChans) expected, bobNumChans)
} }
if aliceStateCorrect && bobStateCorrect {
return
}
<-ticker.C
}
} }
// assertNumConnections asserts number current connections between two peers. // assertNumConnections asserts number current connections between two peers.