From d6c4bfc94f05672dabd9dbbab05e61b8dd5e9434 Mon Sep 17 00:00:00 2001 From: Jiahui Li Date: Fri, 10 Jan 2025 13:05:23 -0600 Subject: [PATCH] Fix unstable tests by adding 'retry_until()' 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) ``` --- test/elixir/test/search_test.exs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/elixir/test/search_test.exs b/test/elixir/test/search_test.exs index edf08f30d5..9cd7623a0f 100644 --- a/test/elixir/test/search_test.exs +++ b/test/elixir/test/search_test.exs @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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}} @@ -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" => %{}} @@ -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}} @@ -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" => %{}}