Skip to content

Commit ca8322e

Browse files
committed
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) ```
1 parent f1f45aa commit ca8322e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

test/elixir/test/partition_search_test.exs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ defmodule PartitionSearchTest do
5656

5757
url = "/#{db_name}/_partition/foo/_design/library/_search/books"
5858
resp = Couch.get(url, query: %{q: "some:field"})
59+
retry_until(fn -> resp.status_code == 200 end)
5960
assert resp.status_code == 200
6061
ids = get_ids(resp)
6162
assert ids == ["foo:10", "foo:2", "foo:4", "foo:6", "foo:8"]
6263

6364
url = "/#{db_name}/_partition/bar/_design/library/_search/books"
6465
resp = Couch.get(url, query: %{q: "some:field"})
66+
retry_until(fn -> resp.status_code == 200 end)
6567
assert resp.status_code == 200
6668
ids = get_ids(resp)
6769
assert ids == ["bar:1", "bar:3", "bar:5", "bar:7", "bar:9"]
@@ -75,6 +77,7 @@ defmodule PartitionSearchTest do
7577

7678
url = "/#{db_name}/_partition/foo/_design/library/_search/books"
7779
resp = Couch.get(url, query: %{q: "some:field"})
80+
retry_until(fn -> resp.status_code == 200 end)
7881
assert resp.status_code == 200
7982
ids = get_ids(resp)
8083
assert ids == ["foo:10", "foo:2", "foo:4", "foo:6", "foo:8"]
@@ -88,18 +91,21 @@ defmodule PartitionSearchTest do
8891

8992
url = "/#{db_name}/_partition/foo/_design/library/_search/books"
9093
resp = Couch.get(url, query: %{q: "some:field", limit: 3})
94+
retry_until(fn -> resp.status_code == 200 end)
9195
assert resp.status_code == 200
9296
ids = get_ids(resp)
9397
assert ids == ["foo:10", "foo:2", "foo:4"]
9498

9599
%{:body => %{"bookmark" => bookmark}} = resp
96100

97101
resp = Couch.get(url, query: %{q: "some:field", limit: 3, bookmark: bookmark})
102+
retry_until(fn -> resp.status_code == 200 end)
98103
assert resp.status_code == 200
99104
ids = get_ids(resp)
100105
assert ids == ["foo:6", "foo:8"]
101106

102107
resp = Couch.get(url, query: %{q: "some:field", limit: 2000, bookmark: bookmark})
108+
retry_until(fn -> resp.status_code == 200 end)
103109
assert resp.status_code == 200
104110
ids = get_ids(resp)
105111
assert ids == ["foo:6", "foo:8"]
@@ -116,6 +122,7 @@ defmodule PartitionSearchTest do
116122

117123
url = "/#{db_name}/_design/library/_search/books"
118124
resp = Couch.post(url, body: %{:q => "some:field", :limit => 1})
125+
retry_until(fn -> resp.status_code == 200 end)
119126
assert resp.status_code == 200
120127
end
121128

@@ -127,6 +134,7 @@ defmodule PartitionSearchTest do
127134

128135
url = "/#{db_name}/_partition/foo/_design/library/_search/books"
129136
resp = Couch.post(url, body: %{:q => "some:field", :limit => 1})
137+
retry_until(fn -> resp.status_code == 200 end)
130138
assert resp.status_code == 200
131139
end
132140

@@ -164,6 +172,7 @@ defmodule PartitionSearchTest do
164172

165173
url = "/#{db_name}/_design/library/_search/books"
166174
resp = Couch.get(url, query: %{q: "some:field"})
175+
retry_until(fn -> resp.status_code == 200 end)
167176
assert resp.status_code == 200
168177
ids = get_ids(resp)
169178
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"])
@@ -177,6 +186,7 @@ defmodule PartitionSearchTest do
177186

178187
url = "/#{db_name}/_design/library/_search/books"
179188
resp = Couch.get(url, query: %{q: "some:field"})
189+
retry_until(fn -> resp.status_code == 200 end)
180190
assert resp.status_code == 200
181191
ids = get_ids(resp)
182192
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"])
@@ -190,6 +200,7 @@ defmodule PartitionSearchTest do
190200

191201
url = "/#{db_name}/_design/library/_search/books"
192202
resp = Couch.get(url, query: %{q: "some:field", limit: 3})
203+
retry_until(fn -> resp.status_code == 200 end)
193204
assert resp.status_code == 200
194205
ids = get_ids(resp)
195206
assert Enum.sort(ids) == Enum.sort(["bar:1", "bar:5", "bar:9"])

test/elixir/test/search_test.exs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ defmodule SearchTest do
7171

7272
url = "/#{db_name}/_design/inventory/_search/fruits"
7373
resp = Couch.get(url, query: %{q: "*:*", include_docs: true})
74+
retry_until(fn -> resp.status_code == 200 end)
7475
assert resp.status_code == 200
7576
ids = get_items(resp)
7677
assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot", "date"])
@@ -84,6 +85,7 @@ defmodule SearchTest do
8485

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

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

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

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

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

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

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

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

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

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

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

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

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

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

290306
%{:body => %{"ranges" => ranges}} = resp

0 commit comments

Comments
 (0)