Skip to content

Commit 60c149f

Browse files
authored
Merge pull request #762 from starius/fix-flaky-autoloop-test
liquidity: fix flaky autoloop test
2 parents 5c88cf8 + 3be5a37 commit 60c149f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

liquidity/autoloop_testcontext_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,26 @@ func (c *autoloopTestCtx) autoloop(step *autoloopStep) {
312312
// Assert that we query the server for a quote for each of our
313313
// recommended swaps. Note that this differs from our set of expected
314314
// swaps because we may get quotes for suggested swaps but then just
315-
// log them.
315+
// log them. The order in c.quoteRequestIn is not deterministic,
316+
// it depends on the order of map traversal (map peerChannels in
317+
// method Manager.SuggestSwaps). So receive from the channel an item
318+
// and then find a corresponding expected item, using amount as a key.
319+
amt2expected := make(map[btcutil.Amount]quoteInRequestResp)
316320
for _, expected := range step.quotesIn {
321+
// Make sure all amounts are unique.
322+
require.NotContains(c.t, amt2expected, expected.request.Amount)
323+
324+
amt2expected[expected.request.Amount] = expected
325+
}
326+
327+
for i := 0; i < len(step.quotesIn); i++ {
317328
request := <-c.quoteRequestIn
329+
330+
// Get the expected item, using amount as a key.
331+
expected, has := amt2expected[request.Amount]
332+
require.True(c.t, has)
333+
delete(amt2expected, request.Amount)
334+
318335
assert.Equal(
319336
c.t, expected.request.Amount, request.Amount,
320337
)

0 commit comments

Comments
 (0)