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 2017-11-02 15:47:59 -07:00
parent 34a165dd12
commit 8a9cf9af16
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
1 changed files with 38 additions and 18 deletions

View File

@ -245,24 +245,44 @@ func numOpenChannelsPending(ctxt context.Context, node *lightningNode) (int, err
// number of pending channels between them.
func assertNumOpenChannelsPending(ctxt context.Context, t *harnessTest,
alice, bob *lightningNode, expected int) {
aliceNumChans, err := numOpenChannelsPending(ctxt, alice)
if err != nil {
t.Fatalf("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)
}
if aliceNumChans != expected {
t.Fatalf("number of pending channels for alice incorrect. "+
"expected %v, got %v", expected, aliceNumChans)
}
if bobNumChans != expected {
t.Fatalf("number of pending channels for bob incorrect. "+
"expected %v, got %v",
expected, bobNumChans)
const nPolls = 10
ticker := time.NewTicker(200 * time.Millisecond)
defer ticker.Stop()
for i := 0; i < nPolls; i++ {
aliceNumChans, err := numOpenChannelsPending(ctxt, alice)
if err != nil {
t.Fatalf("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)
}
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)
}
bobStateCorrect := bobNumChans == expected
if !bobStateCorrect && isLastIteration {
t.Fatalf("number of pending channels for bob incorrect. "+
"expected %v, got %v",
expected, bobNumChans)
}
if aliceStateCorrect && bobStateCorrect {
return
}
<-ticker.C
}
}