Skip to content

Commit

Permalink
Fix unstable tests by adding 'retry_until()'
Browse files Browse the repository at this point in the history
Add `retry_until()` to avoid request timeout error in search_test.exs.

Error logs:
```
1) test search returns all items for GET (SearchTest)
   test/elixir/test/search_test.exs:67
   ** (KeyError) key :status_code not found in: %HTTPotion.ErrorResponse{message: "req_timedout"}
	 code: assert resp.status_code == 200
	 stacktrace:
	   test/elixir/test/search_test.exs:74: (test)
```
  • Loading branch information
jiahuili430 committed Jan 10, 2025
1 parent f1f45aa commit d6c4bfc
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions test/elixir/test/search_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ defmodule SearchTest do

url = "/#{db_name}/_design/inventory/_search/fruits"
resp = Couch.get(url, query: %{q: "*:*", include_docs: true})
assert resp.status_code == 200
retry_until(fn -> resp.status_code == 200 end)
ids = get_items(resp)
assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot", "date"])
end
Expand All @@ -84,7 +84,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})
assert resp.status_code == 200
retry_until(fn -> resp.status_code == 200 end)
ids = get_items(resp)
assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot"])
end
Expand All @@ -97,7 +97,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})
assert resp.status_code == 200
retry_until(fn -> resp.status_code == 200 end)
ids = get_items(resp)
assert Enum.sort(ids) == Enum.sort(["apple", "banana", "date"])
end
Expand All @@ -110,7 +110,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})
assert resp.status_code == 200
retry_until(fn -> resp.status_code == 200 end)
ids = get_items(resp)
assert Enum.sort(ids) == []
end
Expand All @@ -123,7 +123,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)
assert resp.status_code == 200
retry_until(fn -> resp.status_code == 200 end)
ids = get_items(resp)
assert Enum.sort(ids) == []
end
Expand All @@ -137,7 +137,7 @@ defmodule SearchTest do

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

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

url = "/#{db_name}/_design/inventory/_search/fruits"
resp = Couch.post(url, body: %{query: "*:*", drilldown: ["state", "new", "unknown"], include_docs: true})
assert resp.status_code == 200
retry_until(fn -> resp.status_code == 200 end)
ids = get_items(resp)
assert Enum.sort(ids) == Enum.sort(["apple", "banana", "date"])
end
Expand All @@ -176,7 +176,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})
assert resp.status_code == 200
retry_until(fn -> resp.status_code == 200 end)
ids = get_items(resp)
assert Enum.sort(ids) == []
end
Expand All @@ -189,7 +189,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})
assert resp.status_code == 200
retry_until(fn -> resp.status_code == 200 end)
ids = get_items(resp)
assert Enum.sort(ids) == ["apple"]
end
Expand All @@ -202,7 +202,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})
assert resp.status_code == 200
retry_until(fn -> resp.status_code == 200 end)
ids = get_items(resp)
assert Enum.sort(ids) == ["apple"]
end
Expand All @@ -215,7 +215,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\"]}")
assert resp.status_code == 200
retry_until(fn -> resp.status_code == 200 end)
ids = get_items(resp)
assert Enum.sort(ids) == ["apple"]
end
Expand All @@ -240,7 +240,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)})
assert resp.status_code == 200
retry_until(fn -> resp.status_code == 200 end)

%{:body => %{"counts" => counts}} = resp
assert counts == %{"place" => %{"kitchen" => 3, "lobby" => 1}}
Expand All @@ -255,7 +255,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)})
assert resp.status_code == 200
retry_until(fn -> resp.status_code == 200 end)

%{:body => %{"counts" => counts}} = resp
assert counts == %{"place" => %{}}
Expand All @@ -270,7 +270,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)})
assert resp.status_code == 200
retry_until(fn -> resp.status_code == 200 end)

%{:body => %{"ranges" => ranges}} = resp
assert ranges == %{"price" => %{"cheap" => 2, "expensive" => 2}}
Expand All @@ -285,7 +285,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)})
assert resp.status_code == 200
retry_until(fn -> resp.status_code == 200 end)

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

0 comments on commit d6c4bfc

Please sign in to comment.