This is an automated email from the ASF dual-hosted git repository. jiahuili430 pushed a commit to branch add-retry-until-for-search_test.exs in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 8575a52c1fbfa20f5206c952a65c32604c8c4e7e Author: Jiahui Li <[email protected]> AuthorDate: Sat Apr 11 22:16:57 2026 -0500 Revert "Add `retry_until()` to fix flaky elixir search tests" This reverts commit 54bf5738b9937b5a4f66db6808721eba7213d87c. --- test/elixir/test/partition_search_test.exs | 162 +++++++++------------ test/elixir/test/search_test.exs | 217 ++++++++++++----------------- 2 files changed, 158 insertions(+), 221 deletions(-) diff --git a/test/elixir/test/partition_search_test.exs b/test/elixir/test/partition_search_test.exs index 88a3dedb2..9310e701d 100644 --- a/test/elixir/test/partition_search_test.exs +++ b/test/elixir/test/partition_search_test.exs @@ -56,20 +56,16 @@ defmodule PartitionSearchTest do create_ddoc(db_name) url = "/#{db_name}/_partition/foo/_design/library/_search/books" - retry_until(fn -> - resp = Couch.get(url, query: %{q: "some:field"}) - assert_on_status(resp, 200, "Fail to do partitioned search.") - ids = get_ids(resp) - assert ids == ["foo:10", "foo:2", "foo:4", "foo:6", "foo:8"] - end) + resp = Couch.get(url, query: %{q: "some:field"}) + assert_on_status(resp, 200, "Fail to do partitioned search.") + ids = get_ids(resp) + assert ids == ["foo:10", "foo:2", "foo:4", "foo:6", "foo:8"] url = "/#{db_name}/_partition/bar/_design/library/_search/books" - retry_until(fn -> - resp = Couch.get(url, query: %{q: "some:field"}) - assert_on_status(resp, 200, "Fail to do partitioned search.") - ids = get_ids(resp) - assert ids == ["bar:1", "bar:3", "bar:5", "bar:7", "bar:9"] - end) + resp = Couch.get(url, query: %{q: "some:field"}) + assert_on_status(resp, 200, "Fail to do partitioned search.") + ids = get_ids(resp) + assert ids == ["bar:1", "bar:3", "bar:5", "bar:7", "bar:9"] end @tag :with_partitioned_db @@ -79,12 +75,10 @@ defmodule PartitionSearchTest do create_ddoc(db_name) url = "/#{db_name}/_partition/foo/_design/library/_search/books" - retry_until(fn -> - resp = Couch.get(url, query: %{q: "some:field"}) - assert_on_status(resp, 200, "Fail to do partitioned search.") - ids = get_ids(resp) - assert ids == ["foo:10", "foo:2", "foo:4", "foo:6", "foo:8"] - end) + resp = Couch.get(url, query: %{q: "some:field"}) + assert_on_status(resp, 200, "Fail to do partitioned search.") + ids = get_ids(resp) + assert ids == ["foo:10", "foo:2", "foo:4", "foo:6", "foo:8"] end @tag :with_partitioned_db @@ -94,27 +88,25 @@ defmodule PartitionSearchTest do create_ddoc(db_name) url = "/#{db_name}/_partition/foo/_design/library/_search/books" - retry_until(fn -> - resp = Couch.get(url, query: %{q: "some:field", limit: 3}) - assert_on_status(resp, 200, "Fail to do partitioned search.") - ids = get_ids(resp) - assert ids == ["foo:10", "foo:2", "foo:4"] - - %{:body => %{"bookmark" => bookmark}} = resp - - resp = Couch.get(url, query: %{q: "some:field", limit: 3, bookmark: bookmark}) - assert_on_status(resp, 200, "Fail to do partitioned search with a bookmark.") - ids = get_ids(resp) - assert ids == ["foo:6", "foo:8"] - - resp = Couch.get(url, query: %{q: "some:field", limit: 2000, bookmark: bookmark}) - assert_on_status(resp, 200, "Fail to do partition search with an upper bound on the limit.") - ids = get_ids(resp) - assert ids == ["foo:6", "foo:8"] - - resp = Couch.get(url, query: %{q: "some:field", limit: 2001, bookmark: bookmark}) - assert_on_status(resp, 400, "Should fail to do partition search with over limit.") - end) + resp = Couch.get(url, query: %{q: "some:field", limit: 3}) + assert_on_status(resp, 200, "Fail to do partitioned search.") + ids = get_ids(resp) + assert ids == ["foo:10", "foo:2", "foo:4"] + + %{:body => %{"bookmark" => bookmark}} = resp + + resp = Couch.get(url, query: %{q: "some:field", limit: 3, bookmark: bookmark}) + assert_on_status(resp, 200, "Fail to do partitioned search with a bookmark.") + ids = get_ids(resp) + assert ids == ["foo:6", "foo:8"] + + resp = Couch.get(url, query: %{q: "some:field", limit: 2000, bookmark: bookmark}) + assert_on_status(resp, 200, "Fail to do partition search with an upper bound on the limit.") + ids = get_ids(resp) + assert ids == ["foo:6", "foo:8"] + + resp = Couch.get(url, query: %{q: "some:field", limit: 2001, bookmark: bookmark}) + assert_on_status(resp, 400, "Should fail to do partition search with over limit.") end @tag :with_db @@ -124,10 +116,8 @@ defmodule PartitionSearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/library/_search/books" - retry_until(fn -> - resp = Couch.post(url, body: %{:q => "some:field", :limit => 1}) - assert_on_status(resp, 200, "Fail to do POST for non-partitioned db with limit.") - end) + resp = Couch.post(url, body: %{:q => "some:field", :limit => 1}) + assert_on_status(resp, 200, "Fail to do POST for non-partitioned db with limit.") end @tag :with_partitioned_db @@ -137,10 +127,8 @@ defmodule PartitionSearchTest do create_ddoc(db_name) url = "/#{db_name}/_partition/foo/_design/library/_search/books" - retry_until(fn -> - resp = Couch.post(url, body: %{:q => "some:field", :limit => 1}) - assert_on_status(resp, 200, "Fail to do POST for partitioned db with limit.") - end) + resp = Couch.post(url, body: %{:q => "some:field", :limit => 1}) + assert_on_status(resp, 200, "Fail to do POST for partitioned db with limit.") end @tag :with_partitioned_db @@ -150,12 +138,10 @@ defmodule PartitionSearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/library/_search/books" - retry_until(fn -> - resp = Couch.get(url, query: %{q: "some:field"}) - assert_on_status(resp, 400, "Expected a failure to do a global query on partitioned view.") - %{:body => %{"reason" => reason}} = resp - assert Regex.match?(~r/mandatory for queries to this index./, reason) - end) + resp = Couch.get(url, query: %{q: "some:field"}) + assert_on_status(resp, 400, "Expected a failure to do a global query on partitioned view.") + %{:body => %{"reason" => reason}} = resp + assert Regex.match?(~r/mandatory for queries to this index./, reason) end @tag :with_partitioned_db @@ -165,12 +151,10 @@ defmodule PartitionSearchTest do create_ddoc(db_name, options: %{partitioned: false}) url = "/#{db_name}/_partition/foo/_design/library/_search/books" - retry_until(fn -> - resp = Couch.get(url, query: %{q: "some:field"}) - assert_on_status(resp, 400, "Expected a failure to do a query with a global search ddoc.") - %{:body => %{"reason" => reason}} = resp - assert reason == "`partition` not supported on this index" - end) + resp = Couch.get(url, query: %{q: "some:field"}) + assert_on_status(resp, 400, "Expected a failure to do a query with a global search ddoc.") + %{:body => %{"reason" => reason}} = resp + assert reason == "`partition` not supported on this index" end @tag :with_db @@ -180,12 +164,10 @@ defmodule PartitionSearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/library/_search/books" - retry_until(fn -> - resp = Couch.get(url, query: %{q: "some:field"}) - assert_on_status(resp, 200, "Failed to search on non-partitioned dbs.") - ids = get_ids(resp) - assert Enum.sort(ids) == Enum.sort(["bar:1", "bar:5", "bar:9", "foo:2", "bar:3", "foo:4", "foo:6", "bar:7", "foo:8", "foo:10"]) - end) + resp = Couch.get(url, query: %{q: "some:field"}) + assert_on_status(resp, 200, "Failed to search on non-partitioned dbs.") + ids = get_ids(resp) + assert Enum.sort(ids) == Enum.sort(["bar:1", "bar:5", "bar:9", "foo:2", "bar:3", "foo:4", "foo:6", "bar:7", "foo:8", "foo:10"]) end @tag :with_db @@ -195,12 +177,10 @@ defmodule PartitionSearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/library/_search/books" - retry_until(fn -> - resp = Couch.get(url, query: %{q: "some:field"}) - assert_on_status(resp, 200, "Failed to search on non-partitioned dbs without the limit.") - ids = get_ids(resp) - assert Enum.sort(ids) == Enum.sort(["bar:1", "bar:5", "bar:9", "foo:2", "bar:3", "foo:4", "foo:6", "bar:7", "foo:8", "foo:10"]) - end) + resp = Couch.get(url, query: %{q: "some:field"}) + assert_on_status(resp, 200, "Failed to search on non-partitioned dbs without the limit.") + ids = get_ids(resp) + assert Enum.sort(ids) == Enum.sort(["bar:1", "bar:5", "bar:9", "foo:2", "bar:3", "foo:4", "foo:6", "bar:7", "foo:8", "foo:10"]) end @tag :with_db @@ -212,16 +192,14 @@ defmodule PartitionSearchTest do url = "/#{db_name}/_design/library/_search/books" # score order varies by Lucene version, so captured this order first. - retry_until(fn -> - resp = Couch.get(url, query: %{q: "some:field"}) - assert_on_status(resp, 200, "Failed to search on non-partitioned dbs without the limit.") - expected_ids = get_ids(resp) + resp = Couch.get(url, query: %{q: "some:field"}) + assert_on_status(resp, 200, "Failed to search on non-partitioned dbs without the limit.") + expected_ids = get_ids(resp) # Assert that the limit:3 results are the first 3 results from the unlimited search - resp = Couch.get(url, query: %{q: "some:field", limit: 3}) - assert_on_status(resp, 200, "Failed to search on non-partitioned dbs with the limit.") - assert List.starts_with?(expected_ids, get_ids(resp)) - end) + resp = Couch.get(url, query: %{q: "some:field", limit: 3}) + assert_on_status(resp, 200, "Failed to search on non-partitioned dbs with the limit.") + assert List.starts_with?(expected_ids, get_ids(resp)) end @tag :with_db @@ -231,10 +209,8 @@ defmodule PartitionSearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/library/_search/books" - retry_until(fn -> - resp = Couch.get(url, query: %{q: "some:field", limit: 201}) - assert_on_status(resp, 400, "Expected a failure on non-partitioned dbs with over limit.") - end) + resp = Couch.get(url, query: %{q: "some:field", limit: 201}) + assert_on_status(resp, 400, "Expected a failure on non-partitioned dbs with over limit.") end @tag :with_partitioned_db @@ -244,10 +220,8 @@ defmodule PartitionSearchTest do create_ddoc(db_name) url = "/#{db_name}/_partition/foo/_design/library/_search/books" - retry_until(fn -> - resp = Couch.post(url, body: %{q: "some:field", partition: "bar"}) - assert_on_status(resp, 400, "Expected a failure on conflicting partition values.") - end) + resp = Couch.post(url, body: %{q: "some:field", partition: "bar"}) + assert_on_status(resp, 400, "Expected a failure on conflicting partition values.") end @tag :with_partitioned_db @@ -268,14 +242,12 @@ defmodule PartitionSearchTest do fn {key, value} -> url = "/#{db_name}/_partition/foo/_design/library/_search/books" bannedparam = Map.put(body, key, value) - retry_until(fn -> - get_resp = Couch.get(url, query: bannedparam) - %{:body => %{"reason" => get_reason}} = get_resp - assert Regex.match?(~r/are incompatible/, get_reason) - post_resp = Couch.post(url, body: bannedparam) - %{:body => %{"reason" => post_reason}} = post_resp - assert Regex.match?(~r/are incompatible/, post_reason) - end) + get_resp = Couch.get(url, query: bannedparam) + %{:body => %{"reason" => get_reason}} = get_resp + assert Regex.match?(~r/are incompatible/, get_reason) + post_resp = Couch.post(url, body: bannedparam) + %{:body => %{"reason" => post_reason}} = post_resp + assert Regex.match?(~r/are incompatible/, post_reason) end ) end diff --git a/test/elixir/test/search_test.exs b/test/elixir/test/search_test.exs index 87fbeb69b..edf6858cf 100644 --- a/test/elixir/test/search_test.exs +++ b/test/elixir/test/search_test.exs @@ -9,18 +9,19 @@ defmodule SearchTest do """ def create_search_docs(db_name) do - resp = Couch.post("/#{db_name}/_bulk_docs", - headers: ["Content-Type": "application/json"], - body: %{:docs => [ - %{"item" => "apple", "place" => "kitchen", "state" => "new", "price" => 0.99}, - %{"item" => "banana", "place" => "kitchen", "state" => "new", "price" => 1.49}, - %{"item" => "carrot", "place" => "kitchen", "state" => "old", "price" => 0.75}, - %{"item" => "date", "place" => "lobby", "state" => "unknown", "price" => 1.25}, - ]} - ) - assert resp.status_code in [201, 202], - "Cannot create search docs. " <> - "Expected one of [201, 202], got: #{resp.status_code}, body: #{inspect resp.body}" + resp = Couch.post("/#{db_name}/_bulk_docs", + headers: ["Content-Type": "application/json"], + body: %{:docs => [ + %{"item" => "apple", "place" => "kitchen", "state" => "new", "price" => 0.99}, + %{"item" => "banana", "place" => "kitchen", "state" => "new", "price" => 1.49}, + %{"item" => "carrot", "place" => "kitchen", "state" => "old", "price" => 0.75}, + %{"item" => "date", "place" => "lobby", "state" => "unknown", "price" => 1.25}, + ]} + ) + assert resp.status_code in [201, 202], + "Cannot create search docs. " <> + "Expected one of [201, 202], got: #{resp.status_code}, body: #{inspect resp.body}" + end def create_ddoc(db_name, opts \\ %{}) do @@ -73,13 +74,10 @@ defmodule SearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/inventory/_search/fruits" - retry_until(fn -> - resp = Couch.get(url, query: %{q: "*:*", include_docs: true}) - assert_on_status(resp, 200, "Fail to do search.") - - ids = get_items(resp) - assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot", "date"]) - end) + resp = Couch.get(url, query: %{q: "*:*", include_docs: true}) + assert_on_status(resp, 200, "Fail to do search.") + ids = get_items(resp) + assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot", "date"]) end @tag :with_db @@ -89,13 +87,11 @@ defmodule SearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/inventory/_search/fruits" - retry_until(fn -> - resp = Couch.get(url, query: %{q: "*:*", drilldown: :jiffy.encode(["place", "kitchen"]), include_docs: true}) - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.get(url, query: %{q: "*:*", drilldown: :jiffy.encode(["place", "kitchen"]), include_docs: true}) + assert_on_status(resp, 200, "Fail to do search.") - ids = get_items(resp) - assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot"]) - end) + ids = get_items(resp) + assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot"]) end @tag :with_db @@ -105,13 +101,11 @@ defmodule SearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/inventory/_search/fruits" - retry_until(fn -> - resp = Couch.get(url, query: %{q: "*:*", drilldown: :jiffy.encode(["state", "new", "unknown"]), include_docs: true}) - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.get(url, query: %{q: "*:*", drilldown: :jiffy.encode(["state", "new", "unknown"]), include_docs: true}) + assert_on_status(resp, 200, "Fail to do search.") - ids = get_items(resp) - assert Enum.sort(ids) == Enum.sort(["apple", "banana", "date"]) - end) + ids = get_items(resp) + assert Enum.sort(ids) == Enum.sort(["apple", "banana", "date"]) end @tag :with_db @@ -121,13 +115,11 @@ defmodule SearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/inventory/_search/fruits" - retry_until(fn -> - resp = Couch.get(url, query: %{q: "*:*", drilldown: :jiffy.encode([["state", "old"], ["item", "apple"]]), include_docs: true}) - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.get(url, query: %{q: "*:*", drilldown: :jiffy.encode([["state", "old"], ["item", "apple"]]), include_docs: true}) + assert_on_status(resp, 200, "Fail to do search.") - ids = get_items(resp) - assert Enum.sort(ids) == [] - end) + ids = get_items(resp) + assert Enum.sort(ids) == [] end @tag :with_db @@ -137,13 +129,11 @@ defmodule SearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/inventory/_search/fruits?q=*:*&drilldown=[\"state\",\"old\"]&drilldown=[\"item\",\"apple\"]&include_docs=true" - retry_until(fn -> - resp = Couch.get(url) - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.get(url) + assert_on_status(resp, 200, "Fail to do search.") - ids = get_items(resp) - assert Enum.sort(ids) == [] - end) + ids = get_items(resp) + assert Enum.sort(ids) == [] end @@ -154,13 +144,11 @@ defmodule SearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/inventory/_search/fruits" - retry_until(fn -> - resp = Couch.post(url, body: %{q: "*:*", include_docs: true}) - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.post(url, body: %{q: "*:*", include_docs: true}) + assert_on_status(resp, 200, "Fail to do search.") - ids = get_items(resp) - assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot", "date"]) - end) + ids = get_items(resp) + assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot", "date"]) end @tag :with_db @@ -170,13 +158,11 @@ defmodule SearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/inventory/_search/fruits" - retry_until(fn -> - resp = Couch.post(url, body: %{query: "*:*", drilldown: ["place", "kitchen"], include_docs: true}) - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.post(url, body: %{query: "*:*", drilldown: ["place", "kitchen"], include_docs: true}) + assert_on_status(resp, 200, "Fail to do search.") - ids = get_items(resp) - assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot"]) - end) + ids = get_items(resp) + assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot"]) end @tag :with_db @@ -186,13 +172,11 @@ defmodule SearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/inventory/_search/fruits" - retry_until(fn -> - resp = Couch.post(url, body: %{query: "*:*", drilldown: ["state", "new", "unknown"], include_docs: true}) - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.post(url, body: %{query: "*:*", drilldown: ["state", "new", "unknown"], include_docs: true}) + assert_on_status(resp, 200, "Fail to do search.") - ids = get_items(resp) - assert Enum.sort(ids) == Enum.sort(["apple", "banana", "date"]) - end) + ids = get_items(resp) + assert Enum.sort(ids) == Enum.sort(["apple", "banana", "date"]) end @tag :with_db @@ -202,13 +186,11 @@ defmodule SearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/inventory/_search/fruits" - retry_until(fn -> - resp = Couch.post(url, body: %{q: "*:*", drilldown: [["state", "old"], ["item", "apple"]], include_docs: true}) - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.post(url, body: %{q: "*:*", drilldown: [["state", "old"], ["item", "apple"]], include_docs: true}) + assert_on_status(resp, 200, "Fail to do search.") - ids = get_items(resp) - assert Enum.sort(ids) == [] - end) + ids = get_items(resp) + assert Enum.sort(ids) == [] end @tag :with_db @@ -218,13 +200,11 @@ defmodule SearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/inventory/_search/fruits" - retry_until(fn -> - resp = Couch.post(url, body: %{q: "*:*", drilldown: [["place", "kitchen"], ["state", "new"], ["item", "apple"]], include_docs: true}) - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.post(url, body: %{q: "*:*", drilldown: [["place", "kitchen"], ["state", "new"], ["item", "apple"]], include_docs: true}) + assert_on_status(resp, 200, "Fail to do search.") - ids = get_items(resp) - assert Enum.sort(ids) == ["apple"] - end) + ids = get_items(resp) + assert Enum.sort(ids) == ["apple"] end @tag :with_db @@ -234,13 +214,11 @@ defmodule SearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/inventory/_search/fruits" - retry_until(fn -> - resp = Couch.post(url, body: %{q: "*:*", drilldown: [["state", "old", "new"], ["item", "apple"]], include_docs: true}) - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.post(url, body: %{q: "*:*", drilldown: [["state", "old", "new"], ["item", "apple"]], include_docs: true}) + assert_on_status(resp, 200, "Fail to do search.") - ids = get_items(resp) - assert Enum.sort(ids) == ["apple"] - end) + ids = get_items(resp) + assert Enum.sort(ids) == ["apple"] end @tag :with_db @@ -250,13 +228,11 @@ defmodule SearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/inventory/_search/fruits" - retry_until(fn -> - resp = Couch.post(url, body: "{\"include_docs\": true, \"q\": \"*:*\", \"drilldown\": [\"state\", \"old\"], \"drilldown\": [\"item\", \"apple\"]}") - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.post(url, body: "{\"include_docs\": true, \"q\": \"*:*\", \"drilldown\": [\"state\", \"old\"], \"drilldown\": [\"item\", \"apple\"]}") + assert_on_status(resp, 200, "Fail to do search.") - ids = get_items(resp) - assert Enum.sort(ids) == ["apple"] - end) + ids = get_items(resp) + assert Enum.sort(ids) == ["apple"] end @tag :with_db @@ -266,10 +242,8 @@ defmodule SearchTest do create_ddoc(db_name) create_invalid_ddoc(db_name) - retry_until(fn -> - resp = Couch.post("/#{db_name}/_search_cleanup") - assert_on_status(resp, [201, 202], "Fail to do a _search_cleanup.") - end) + resp = Couch.post("/#{db_name}/_search_cleanup") + assert_on_status(resp, [201, 202], "Fail to do a _search_cleanup.") end @tag :with_db @@ -280,13 +254,11 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" counts = ["place"] - retry_until(fn -> - resp = Couch.get(url, query: %{q: "*:*", limit: 0, counts: :jiffy.encode(counts)}) - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.get(url, query: %{q: "*:*", limit: 0, counts: :jiffy.encode(counts)}) + assert_on_status(resp, 200, "Fail to do search.") - %{:body => %{"counts" => counts}} = resp - assert counts == %{"place" => %{"kitchen" => 3, "lobby" => 1}} - end) + %{:body => %{"counts" => counts}} = resp + assert counts == %{"place" => %{"kitchen" => 3, "lobby" => 1}} end @tag :with_db @@ -297,13 +269,11 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" counts = ["place"] - retry_until(fn -> - resp = Couch.get(url, query: %{q: "item:tomato", limit: 0, counts: :jiffy.encode(counts)}) - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.get(url, query: %{q: "item:tomato", limit: 0, counts: :jiffy.encode(counts)}) + assert_on_status(resp, 200, "Fail to do search.") - %{:body => %{"counts" => counts}} = resp - assert counts == %{"place" => %{}} - end) + %{:body => %{"counts" => counts}} = resp + assert counts == %{"place" => %{}} end @tag :with_db @@ -314,13 +284,11 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" ranges = %{"price" => %{"cheap" => "[0 TO 0.99]", "expensive" => "[1.00 TO Infinity]"}} - retry_until(fn -> - resp = Couch.get(url, query: %{q: "*:*", limit: 0, ranges: :jiffy.encode(ranges)}) - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.get(url, query: %{q: "*:*", limit: 0, ranges: :jiffy.encode(ranges)}) + assert_on_status(resp, 200, "Fail to do search.") - %{:body => %{"ranges" => ranges}} = resp - assert ranges == %{"price" => %{"cheap" => 2, "expensive" => 2}} - end) + %{:body => %{"ranges" => ranges}} = resp + assert ranges == %{"price" => %{"cheap" => 2, "expensive" => 2}} end @tag :with_db @@ -331,13 +299,11 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" ranges = %{"price" => %{}} - retry_until(fn -> - resp = Couch.get(url, query: %{q: "*:*", limit: 0, ranges: :jiffy.encode(ranges)}) - assert_on_status(resp, 200, "Fail to do search.") + resp = Couch.get(url, query: %{q: "*:*", limit: 0, ranges: :jiffy.encode(ranges)}) + assert_on_status(resp, 200, "Fail to do search.") - %{:body => %{"ranges" => ranges}} = resp - assert ranges == %{"price" => %{}} - end) + %{:body => %{"ranges" => ranges}} = resp + assert ranges == %{"price" => %{}} end @tag :with_db @@ -347,19 +313,18 @@ defmodule SearchTest do create_ddoc(db_name) url = "/#{db_name}/_design/inventory/_search/fruits" - retry_until(fn -> - resp = Couch.get(url, query: %{q: "*:*", group_field: "state"}) - assert_on_status(resp, 200, "Fail to do search.") - - %{:body => %{"groups" => groups}} = resp - assert length(groups) == 3 - Enum.each(groups, fn g -> - case g["by"] do - "new" -> assert g["total_rows"] == 2 - "old" -> assert g["total_rows"] == 1 - "unknown" -> assert g["total_rows"] == 1 - end - end) + ranges = %{"price" => %{}} + resp = Couch.get(url, query: %{q: "*:*", group_field: "state"}) + assert_on_status(resp, 200, "Fail to do search.") + + %{:body => %{"groups" => groups}} = resp + assert length(groups) == 3 + Enum.each(groups, fn g -> + case g["by"] do + "new" -> assert g["total_rows"] == 2 + "old" -> assert g["total_rows"] == 1 + "unknown" -> assert g["total_rows"] == 1 + end end) end
