Skip to content

Commit

Permalink
Fix flaky changes async test
Browse files Browse the repository at this point in the history
Try to prevent failures like:
```
  1) test continuous filtered changes (ChangesAsyncTest)
     src/couchdb/test/elixir/test/changes_async_test.exs:193
     Expected truthy, got false
     code: assert Enum.member?(changes_ids, "rusty")
     arguments:

         # 1
         ["bingo"]

         # 2
         "rusty"

     stacktrace:
       src/couchdb/test/elixir/test/changes_async_test.exs:220: (test)

```
  • Loading branch information
jaydoane committed Apr 3, 2024
1 parent 1b5cd8f commit 33bfa13
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions test/elixir/test/changes_async_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,18 @@ defmodule ChangesAsyncTest do
:ok = wait_for_headers(req_id.id, 200)
create_doc(db_name, %{_id: "rusty", bop: "plankton"})

changes = process_response(req_id.id, &parse_changes_line_chunk/1)
retry_until(fn ->
changes = process_response(req_id.id, &parse_changes_line_chunk/1)

changes_ids =
changes
|> Enum.filter(fn p -> Map.has_key?(p, "id") end)
|> Enum.map(fn p -> p["id"] end)
changes_ids =
changes
|> Enum.filter(fn p -> Map.has_key?(p, "id") end)
|> Enum.map(fn p -> p["id"] end)

assert Enum.member?(changes_ids, "bingo")
assert Enum.member?(changes_ids, "rusty")
assert length(changes_ids) == 2
Enum.member?(changes_ids, "bingo") and
Enum.member?(changes_ids, "rusty") and
length(changes_ids) == 2
end)
end

@tag :with_db
Expand Down

0 comments on commit 33bfa13

Please sign in to comment.