autopilot/agent_test: wait for expected num chans and balance
Previously we waited only for the number of channels to become what we expected, but this wasn't enough. Sometimes the agent had't yet updated its internal balance, causing the test to fail with an unexpected balance.
This commit is contained in:
parent
bf7f392c11
commit
68f7642564
@ -1259,34 +1259,40 @@ func TestAgentChannelSizeAllocation(t *testing.T) {
|
|||||||
waitForNumChans := func(expChans int) {
|
waitForNumChans := func(expChans int) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
|
var (
|
||||||
|
numChans int
|
||||||
|
balance btcutil.Amount
|
||||||
|
)
|
||||||
|
|
||||||
Loop:
|
Loop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case arg := <-testCtx.constraints.moreChanArgs:
|
case arg := <-testCtx.constraints.moreChanArgs:
|
||||||
|
numChans = len(arg.chans)
|
||||||
|
balance = arg.balance
|
||||||
|
|
||||||
// As long as the number of existing channels
|
// As long as the number of existing channels
|
||||||
// is below our expected number of channels,
|
// is below our expected number of channels,
|
||||||
// we'll keep responding with "no more
|
// and the balance is not what we expect, we'll
|
||||||
// channels".
|
// keep responding with "no more channels".
|
||||||
if len(arg.chans) != expChans {
|
if numChans == expChans &&
|
||||||
select {
|
balance == testCtx.walletBalance {
|
||||||
case testCtx.constraints.moreChansResps <- moreChansResp{0, 0}:
|
break Loop
|
||||||
case <-time.After(time.Second * 3):
|
|
||||||
t.Fatalf("heuristic wasn't " +
|
|
||||||
"queried in time")
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if arg.balance != testCtx.walletBalance {
|
select {
|
||||||
t.Fatalf("expectd agent to have %v "+
|
case testCtx.constraints.moreChansResps <- moreChansResp{0, 0}:
|
||||||
"balance, had %v",
|
case <-time.After(time.Second * 3):
|
||||||
testCtx.walletBalance,
|
t.Fatalf("heuristic wasn't queried " +
|
||||||
arg.balance)
|
"in time")
|
||||||
}
|
}
|
||||||
break Loop
|
|
||||||
|
|
||||||
case <-time.After(time.Second * 3):
|
case <-time.After(time.Second * 3):
|
||||||
t.Fatalf("heuristic wasn't queried in time")
|
t.Fatalf("did not receive expected "+
|
||||||
|
"channels(%d) and balance(%d), "+
|
||||||
|
"instead got %d and %d", expChans,
|
||||||
|
testCtx.walletBalance, numChans,
|
||||||
|
balance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user