Improve all_docs_test robustness
authorJay Doane <jay.s.doane@gmail.com>
Sun, 23 Dec 2018 05:46:11 +0000 (21:46 -0800)
committerJay Doane <jay.s.doane@gmail.com>
Sun, 23 Dec 2018 05:46:11 +0000 (21:46 -0800)
Wrap deleted element assertions in retry_until to prevent timing related
failures like:

AllDocsTest
  * test All Docs tests (331.1ms)

  1) test All Docs tests (AllDocsTest)
     test/all_docs_test.exs:15
     Assertion with == failed
     code:  assert length(deleted) == 1
     left:  0
     right: 1
     stacktrace:
       test/all_docs_test.exs:72: (test)

test/elixir/test/all_docs_test.exs

index 1869277..b8f21e7 100644 (file)
@@ -69,9 +69,12 @@ defmodule AllDocsTest do
     assert Couch.delete("/#{db_name}/1", query: %{:rev => doc1["_rev"]}).body["ok"]
     changes = Couch.get("/#{db_name}/_changes").body["results"]
     assert length(changes) == 4
-    deleted = Enum.filter(changes, fn row -> row["deleted"] end)
-    assert length(deleted) == 1
-    assert hd(deleted)["id"] == "1"
+
+    retry_until(fn ->
+      deleted = Enum.filter(changes, fn row -> row["deleted"] end)
+      assert length(deleted) == 1
+      assert hd(deleted)["id"] == "1"
+    end)
 
     # (remember old seq)
     orig_doc = Enum.find(changes, fn row -> row["id"] == "3" end)