Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unstable tests by adding 'retry_until()' #5394

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/elixir/test/search_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ defmodule SearchTest do

url = "/#{db_name}/_design/inventory/_search/fruits"
resp = Couch.get(url, query: %{q: "*:*", include_docs: true})
retry_until(fn -> resp.status_code == 200 end)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can do on extra single assert below, just to ensure it's not flapping and once it's hits 200 it stays 200

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does retry_until work? Do it have any magic to throw an exception and the whole test body up to that point is retried. Otherwise, if it's as simple as it looks in retry_until(fn -> resp.status_code == 200 end) we'd just be checking the same response and always fail, then we'd have to retry the whole Couch.get(...)?

assert resp.status_code == 200
ids = get_items(resp)
assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot", "date"])
Expand All @@ -84,6 +85,7 @@ defmodule SearchTest do

url = "/#{db_name}/_design/inventory/_search/fruits"
resp = Couch.get(url, query: %{q: "*:*", drilldown: :jiffy.encode(["place", "kitchen"]), include_docs: true})
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200
ids = get_items(resp)
assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot"])
Expand All @@ -97,6 +99,7 @@ defmodule SearchTest do

url = "/#{db_name}/_design/inventory/_search/fruits"
resp = Couch.get(url, query: %{q: "*:*", drilldown: :jiffy.encode(["state", "new", "unknown"]), include_docs: true})
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200
ids = get_items(resp)
assert Enum.sort(ids) == Enum.sort(["apple", "banana", "date"])
Expand All @@ -110,6 +113,7 @@ defmodule SearchTest do

url = "/#{db_name}/_design/inventory/_search/fruits"
resp = Couch.get(url, query: %{q: "*:*", drilldown: :jiffy.encode([["state", "old"], ["item", "apple"]]), include_docs: true})
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200
ids = get_items(resp)
assert Enum.sort(ids) == []
Expand All @@ -123,6 +127,7 @@ defmodule SearchTest do

url = "/#{db_name}/_design/inventory/_search/fruits?q=*:*&drilldown=[\"state\",\"old\"]&drilldown=[\"item\",\"apple\"]&include_docs=true"
resp = Couch.get(url)
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200
ids = get_items(resp)
assert Enum.sort(ids) == []
Expand All @@ -137,6 +142,7 @@ defmodule SearchTest do

url = "/#{db_name}/_design/inventory/_search/fruits"
resp = Couch.post(url, body: %{q: "*:*", include_docs: true})
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200
ids = get_items(resp)
assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot", "date"])
Expand All @@ -150,6 +156,7 @@ defmodule SearchTest do

url = "/#{db_name}/_design/inventory/_search/fruits"
resp = Couch.post(url, body: %{query: "*:*", drilldown: ["place", "kitchen"], include_docs: true})
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200
ids = get_items(resp)
assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot"])
Expand All @@ -163,6 +170,7 @@ defmodule SearchTest do

url = "/#{db_name}/_design/inventory/_search/fruits"
resp = Couch.post(url, body: %{query: "*:*", drilldown: ["state", "new", "unknown"], include_docs: true})
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200
ids = get_items(resp)
assert Enum.sort(ids) == Enum.sort(["apple", "banana", "date"])
Expand All @@ -176,6 +184,7 @@ defmodule SearchTest do

url = "/#{db_name}/_design/inventory/_search/fruits"
resp = Couch.post(url, body: %{q: "*:*", drilldown: [["state", "old"], ["item", "apple"]], include_docs: true})
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200
ids = get_items(resp)
assert Enum.sort(ids) == []
Expand All @@ -189,6 +198,7 @@ defmodule SearchTest do

url = "/#{db_name}/_design/inventory/_search/fruits"
resp = Couch.post(url, body: %{q: "*:*", drilldown: [["place", "kitchen"], ["state", "new"], ["item", "apple"]], include_docs: true})
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200
ids = get_items(resp)
assert Enum.sort(ids) == ["apple"]
Expand All @@ -202,6 +212,7 @@ defmodule SearchTest do

url = "/#{db_name}/_design/inventory/_search/fruits"
resp = Couch.post(url, body: %{q: "*:*", drilldown: [["state", "old", "new"], ["item", "apple"]], include_docs: true})
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200
ids = get_items(resp)
assert Enum.sort(ids) == ["apple"]
Expand All @@ -215,6 +226,7 @@ defmodule SearchTest do

url = "/#{db_name}/_design/inventory/_search/fruits"
resp = Couch.post(url, body: "{\"include_docs\": true, \"q\": \"*:*\", \"drilldown\": [\"state\", \"old\"], \"drilldown\": [\"item\", \"apple\"]}")
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200
ids = get_items(resp)
assert Enum.sort(ids) == ["apple"]
Expand All @@ -240,6 +252,7 @@ defmodule SearchTest do
url = "/#{db_name}/_design/inventory/_search/fruits"
counts = ["place"]
resp = Couch.get(url, query: %{q: "*:*", limit: 0, counts: :jiffy.encode(counts)})
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200

%{:body => %{"counts" => counts}} = resp
Expand All @@ -255,6 +268,7 @@ defmodule SearchTest do
url = "/#{db_name}/_design/inventory/_search/fruits"
counts = ["place"]
resp = Couch.get(url, query: %{q: "item:tomato", limit: 0, counts: :jiffy.encode(counts)})
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200

%{:body => %{"counts" => counts}} = resp
Expand All @@ -270,6 +284,7 @@ defmodule SearchTest do
url = "/#{db_name}/_design/inventory/_search/fruits"
ranges = %{"price" => %{"cheap" => "[0 TO 0.99]", "expensive" => "[1.00 TO Infinity]"}}
resp = Couch.get(url, query: %{q: "*:*", limit: 0, ranges: :jiffy.encode(ranges)})
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200

%{:body => %{"ranges" => ranges}} = resp
Expand All @@ -285,6 +300,7 @@ defmodule SearchTest do
url = "/#{db_name}/_design/inventory/_search/fruits"
ranges = %{"price" => %{}}
resp = Couch.get(url, query: %{q: "*:*", limit: 0, ranges: :jiffy.encode(ranges)})
retry_until(fn -> resp.status_code == 200 end)
assert resp.status_code == 200

%{:body => %{"ranges" => ranges}} = resp
Expand Down