From c3d67179b7a53cad4e2f83da20844ba8de3c04bd Mon Sep 17 00:00:00 2001 From: garren smith Date: Fri, 15 Feb 2019 15:42:57 +0200 Subject: Fix elixir tests and add back to make check (#1918) * Add back elixir tests to make check * Fix reliability of the flaky elixir tests --- Makefile | 1 + test/elixir/test/basics_test.exs | 2 +- test/elixir/test/compact_test.exs | 26 ++++++++++++------- test/elixir/test/conflicts_test.exs | 13 ++++++---- test/elixir/test/delayed_commits_test.exs | 4 +++ test/elixir/test/lots_of_docs_test.exs | 34 +++++++++++++------------ test/elixir/test/partition_ddoc_test.exs | 21 ++++++++------- test/elixir/test/partition_view_update_test.exs | 24 +++++++++-------- test/elixir/test/replication_test.exs | 4 +-- 9 files changed, 76 insertions(+), 53 deletions(-) diff --git a/Makefile b/Makefile index 208d16985..62d2f3443 100644 --- a/Makefile +++ b/Makefile @@ -147,6 +147,7 @@ check: all @$(MAKE) eunit @$(MAKE) javascript @$(MAKE) mango-test + @$(MAKE) elixir # @$(MAKE) build-test diff --git a/test/elixir/test/basics_test.exs b/test/elixir/test/basics_test.exs index 8fc0b1d70..3491ef5a3 100644 --- a/test/elixir/test/basics_test.exs +++ b/test/elixir/test/basics_test.exs @@ -151,7 +151,7 @@ defmodule BasicsTest do assert Couch.post("/#{db_name}", body: %{:_id => "2", :a => 3, :b => 9}).body["ok"] assert Couch.post("/#{db_name}", body: %{:_id => "3", :a => 4, :b => 16}).body["ok"] assert Couch.put("/#{db_name}/_design/foo", body: map_doc).body["ok"] - assert Couch.put("/#{db_name}/_design/bar", body: red_doc).body["ok"] + assert Couch.put("/#{db_name}/_design/bar", body: red_doc, query: [w: 3]).body["ok"] assert Couch.get("/#{db_name}").body["doc_count"] == 6 # Initial view query test diff --git a/test/elixir/test/compact_test.exs b/test/elixir/test/compact_test.exs index 5efeee670..e60397f51 100644 --- a/test/elixir/test/compact_test.exs +++ b/test/elixir/test/compact_test.exs @@ -24,18 +24,26 @@ defmodule CompactTest do assert orig_data_size < orig_disk_size delete(db, docs) + + retry_until(fn -> + deleted_data_size = get_info(db)["data_size"] + assert deleted_data_size > orig_data_size + end) + deleted_data_size = get_info(db)["data_size"] - assert deleted_data_size > orig_data_size compact(db) - assert get_info(db)["instance_start_time"] == start_time - assert_attachment_available(db) - info = get_info(db) - final_data_size = info["data_size"] - final_disk_size = info["disk_size"] - assert final_data_size < final_disk_size - assert is_integer(final_data_size) and is_integer(final_disk_size) - assert final_data_size < deleted_data_size + + retry_until(fn -> + assert get_info(db)["instance_start_time"] == start_time + assert_attachment_available(db) + info = get_info(db) + final_data_size = info["data_size"] + final_disk_size = info["disk_size"] + assert final_data_size < final_disk_size + assert is_integer(final_data_size) and is_integer(final_disk_size) + assert final_data_size < deleted_data_size + end) end defp assert_attachment_available(db) do diff --git a/test/elixir/test/conflicts_test.exs b/test/elixir/test/conflicts_test.exs index 8344a27d9..a45f5c4ed 100644 --- a/test/elixir/test/conflicts_test.exs +++ b/test/elixir/test/conflicts_test.exs @@ -24,13 +24,16 @@ defmodule RevisionTest do doc2 = %{doc | a: 2, b: 2} # doc updated with new _rev _doc = rev(doc, put(db, doc)) - assert_conflict(Couch.put("/#{db}/#{doc2._id}", body: doc2)) - resp = Couch.get("/#{db}/_changes") - assert length(resp.body["results"]) == 1 + retry_until(fn -> + assert_conflict(Couch.put("/#{db}/#{doc2._id}", body: doc2)) - doc2 = Map.delete(doc2, :_rev) - assert_conflict(Couch.put("/#{db}/#{doc2._id}", body: doc2)) + resp = Couch.get("/#{db}/_changes") + assert length(resp.body["results"]) == 1 + + doc2 = Map.delete(doc2, :_rev) + assert_conflict(Couch.put("/#{db}/#{doc2._id}", body: doc2)) + end) end @tag :with_db diff --git a/test/elixir/test/delayed_commits_test.exs b/test/elixir/test/delayed_commits_test.exs index e80d0bdfb..9b00a5916 100644 --- a/test/elixir/test/delayed_commits_test.exs +++ b/test/elixir/test/delayed_commits_test.exs @@ -7,8 +7,12 @@ defmodule DelayedCommitsTest do Note that delayed_commits is deprecated in 2.0, so this is a minimal test to show it still works. delayed_commits will be removed in 3.0. + + This test is now skipped. Its a bit of a flaky test so no point running it + since we are removing this feature. """ + @tag :pending @tag config: [ {"couchdb", "delayed_commits", "true"} ] diff --git a/test/elixir/test/lots_of_docs_test.exs b/test/elixir/test/lots_of_docs_test.exs index b217e0682..252de7aa3 100644 --- a/test/elixir/test/lots_of_docs_test.exs +++ b/test/elixir/test/lots_of_docs_test.exs @@ -32,22 +32,24 @@ defmodule LotsOfDocsTest do assert Map.fetch!(Enum.at(rows, index), "key") === value end) - %{"rows" => desc_rows, "total_rows" => desc_total_rows} = - Couch.get( - "/#{db_name}/_all_docs", - query: %{:descending => true} - ).body - - assert desc_total_rows === Enum.count(@docs_range) - assert desc_total_rows === Enum.count(desc_rows) - - @docs_range - |> Enum.map(fn i -> Integer.to_string(i) end) - |> Enum.sort() - |> Enum.reverse() - |> Enum.with_index() - |> Enum.each(fn {value, index} -> - assert Map.fetch!(Enum.at(desc_rows, index), "key") === value + retry_until(fn -> + %{"rows" => desc_rows, "total_rows" => desc_total_rows} = + Couch.get( + "/#{db_name}/_all_docs", + query: %{:descending => true} + ).body + + assert desc_total_rows === Enum.count(@docs_range) + assert desc_total_rows === Enum.count(desc_rows) + + @docs_range + |> Enum.map(fn i -> Integer.to_string(i) end) + |> Enum.sort() + |> Enum.reverse() + |> Enum.with_index() + |> Enum.each(fn {value, index} -> + assert Map.fetch!(Enum.at(desc_rows, index), "key") === value + end) end) end diff --git a/test/elixir/test/partition_ddoc_test.exs b/test/elixir/test/partition_ddoc_test.exs index 4b1f00d8b..ef1147f3f 100644 --- a/test/elixir/test/partition_ddoc_test.exs +++ b/test/elixir/test/partition_ddoc_test.exs @@ -145,7 +145,7 @@ defmodule PartitionDDocTest do test "GET /dbname/_all_docs?key=$ddoc_id", context do db_name = context[:db_name] - resp = Couch.put("/#{db_name}/_design/foo", body: %{stuff: "here"}) + resp = Couch.put("/#{db_name}/_design/foo", body: %{stuff: "here"}, query: [w: 3]) assert resp.status_code == 201 resp = Couch.get("/#{db_name}/_all_docs", query: [key: "\"_design/foo\""]) @@ -153,19 +153,22 @@ defmodule PartitionDDocTest do %{body: body} = resp assert length(body["rows"]) == 1 - %{"rows" => [%{"id" => "_design/foo"}]} = body + assert %{"rows" => [%{"id" => "_design/foo"}]} = body end test "GET /dbname/_design_docs", context do db_name = context[:db_name] - resp = Couch.put("/#{db_name}/_design/foo", body: %{stuff: "here"}) - assert resp.status_code == 201 - resp = Couch.get("/#{db_name}/_design_docs") - assert resp.status_code == 200 - %{body: body} = resp + retry_until(fn -> + resp = Couch.put("/#{db_name}/_design/foo", body: %{stuff: "here"}) + assert resp.status_code == 201 - assert length(body["rows"]) == 1 - %{"rows" => [%{"id" => "_design/foo"}]} = body + resp = Couch.get("/#{db_name}/_design_docs") + assert resp.status_code == 200 + %{body: body} = resp + + assert length(body["rows"]) == 1 + %{"rows" => [%{"id" => "_design/foo"}]} = body + end) end end diff --git a/test/elixir/test/partition_view_update_test.exs b/test/elixir/test/partition_view_update_test.exs index 8f298b391..516943b29 100644 --- a/test/elixir/test/partition_view_update_test.exs +++ b/test/elixir/test/partition_view_update_test.exs @@ -59,18 +59,20 @@ defmodule PartitionViewUpdateTest do Couch.put("/#{db_name}/foo:1", body: %{some: "field"}) - resp = - Couch.get( - url, - query: %{ - update: "false", - limit: 3 - } - ) + retry_until(fn -> + resp = + Couch.get( + url, + query: %{ + update: "false", + limit: 3 + } + ) - assert resp.status_code == 200 - ids = get_ids(resp) - assert ids == ["foo:2", "foo:4", "foo:6"] + assert resp.status_code == 200 + ids = get_ids(resp) + assert ids == ["foo:2", "foo:4", "foo:6"] + end) end @tag :with_partitioned_db diff --git a/test/elixir/test/replication_test.exs b/test/elixir/test/replication_test.exs index 70db01ebc..9a20f78d2 100644 --- a/test/elixir/test/replication_test.exs +++ b/test/elixir/test/replication_test.exs @@ -1606,7 +1606,7 @@ defmodule ReplicationTest do def get_db_changes(db_name, query \\ %{}) do resp = Couch.get("/#{db_name}/_changes", query: query) - assert HTTPotion.Response.success?(resp), "#{inspect(resp)}" + assert HTTPotion.Response.success?(resp), "#{inspect(resp)} #{inspect(query)}" resp.body end @@ -1661,7 +1661,7 @@ defmodule ReplicationTest do def wait_for_repl(src_db_name, repl_id, expect_revs_checked, wait_left) do task = get_task(repl_id, 0) - through_seq = task["through_seq"] + through_seq = task["through_seq"] || "0" revs_checked = task["revisions_checked"] changes = get_db_changes(src_db_name, %{:since => through_seq}) -- cgit v1.2.1