iilyak closed pull request #1829: Elixir test improvements
URL: https://github.com/apache/couchdb/pull/1829
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/test/elixir/lib/couch/db_test.ex b/test/elixir/lib/couch/db_test.ex
index efd02f129d..8992376350 100644
--- a/test/elixir/lib/couch/db_test.ex
+++ b/test/elixir/lib/couch/db_test.ex
@@ -156,21 +156,21 @@ defmodule Couch.DBTest do
def create_db(db_name) do
resp = Couch.put("/#{db_name}")
- assert resp.status_code == 201
+ assert resp.status_code in [201, 202]
assert resp.body == %{"ok" => true}
{:ok, resp}
end
def delete_db(db_name) do
resp = Couch.delete("/#{db_name}")
- assert resp.status_code == 200
+ assert resp.status_code in [200, 202]
assert resp.body == %{"ok" => true}
{:ok, resp}
end
def create_doc(db_name, body) do
resp = Couch.post("/#{db_name}", body: body)
- assert resp.status_code == 201
+ assert resp.status_code in [201, 202]
assert resp.body["ok"]
{:ok, resp}
end
diff --git a/test/elixir/test/all_docs_test.exs
b/test/elixir/test/all_docs_test.exs
index 21dcb616b3..b8f21e7c08 100644
--- a/test/elixir/test/all_docs_test.exs
+++ b/test/elixir/test/all_docs_test.exs
@@ -46,7 +46,8 @@ defmodule AllDocsTest do
# Confirm that queries may assume raw collation
resp =
- Couch.get("/#{db_name}/_all_docs",
+ Couch.get(
+ "/#{db_name}/_all_docs",
query: %{
:startkey => "\"org.couchdb.user:\"",
:endkey => "\"org.couchdb.user;\""
@@ -68,9 +69,12 @@ defmodule AllDocsTest do
assert Couch.delete("/#{db_name}/1", query: %{:rev =>
doc1["_rev"]}).body["ok"]
changes = Couch.get("/#{db_name}/_changes").body["results"]
assert length(changes) == 4
- deleted = Enum.filter(changes, fn row -> row["deleted"] end)
- assert length(deleted) == 1
- assert hd(deleted)["id"] == "1"
+
+ retry_until(fn ->
+ deleted = Enum.filter(changes, fn row -> row["deleted"] end)
+ assert length(deleted) == 1
+ assert hd(deleted)["id"] == "1"
+ end)
# (remember old seq)
orig_doc = Enum.find(changes, fn row -> row["id"] == "3" end)
@@ -99,7 +103,8 @@ defmodule AllDocsTest do
# Test _all_docs with keys
rows =
- Couch.post("/#{db_name}/_all_docs",
+ Couch.post(
+ "/#{db_name}/_all_docs",
query: %{:include_docs => true},
body: %{:keys => ["1"]}
).body["rows"]
@@ -124,18 +129,23 @@ defmodule AllDocsTest do
:value => "Z"
}
- assert Couch.put("/#{db_name}/3", query: %{:new_edits => false}, body:
conflicted_doc1).body[
- "ok"
- ]
+ assert Couch.put(
+ "/#{db_name}/3",
+ query: %{:new_edits => false},
+ body: conflicted_doc1
+ ).body["ok"]
- assert Couch.put("/#{db_name}/3", query: %{:new_edits => false}, body:
conflicted_doc2).body[
- "ok"
- ]
+ assert Couch.put(
+ "/#{db_name}/3",
+ query: %{:new_edits => false},
+ body: conflicted_doc2
+ ).body["ok"]
win_rev = Couch.get("/#{db_name}/3").body
changes =
- Couch.get("/#{db_name}/_changes",
+ Couch.get(
+ "/#{db_name}/_changes",
query: %{:include_docs => true, :conflicts => true, :style =>
"all_docs"}
).body["results"]
@@ -147,7 +157,8 @@ defmodule AllDocsTest do
assert length(doc3["doc"]["_conflicts"]) == 2
rows =
- Couch.get("/#{db_name}/_all_docs",
+ Couch.get(
+ "/#{db_name}/_all_docs",
query: %{:include_docs => true, :conflicts => true}
).body["rows"]
@@ -166,7 +177,8 @@ defmodule AllDocsTest do
assert Couch.post("/#{db_name}", body: %{:_id => "a", :foo =>
"a"}).body["ok"]
rows =
- Couch.get("/#{db_name}/_all_docs",
+ Couch.get(
+ "/#{db_name}/_all_docs",
query: %{:startkey => "\"Z\"", :endkey => "\"Z\""}
).body["rows"]
diff --git a/test/elixir/test/cluster_with_quorum_test.exs
b/test/elixir/test/cluster_with_quorum_test.exs
index 76fc9b4490..d07b18fea7 100644
--- a/test/elixir/test/cluster_with_quorum_test.exs
+++ b/test/elixir/test/cluster_with_quorum_test.exs
@@ -51,7 +51,8 @@ defmodule WithQuorumTest do
Couch.put("/#{db_name}")
resp =
- Couch.post("/#{context[:db_name]}",
+ Couch.post(
+ "/#{context[:db_name]}",
query: %{:w => 3},
body: %{:_id => "0", :a => 1}
)
@@ -63,7 +64,8 @@ defmodule WithQuorumTest do
rev = resp.body["_rev"]
resp =
- Couch.put("/#{context[:db_name]}/0",
+ Couch.put(
+ "/#{context[:db_name]}/0",
query: %{:w => 3},
body: %{:_id => "0", :_rev => rev, :a => 2}
)
@@ -85,7 +87,8 @@ defmodule WithQuorumTest do
db_name = context[:db_name]
Couch.put("/#{db_name}")
- Couch.post("/#{context[:db_name]}",
+ Couch.post(
+ "/#{context[:db_name]}",
body: %{:_id => "0", :a => 1}
)
@@ -130,7 +133,8 @@ defmodule WithQuorumTest do
rev = resp.body["rev"]
resp =
- Couch.put("/#{context[:db_name]}/0/foo.txt",
+ Couch.put(
+ "/#{context[:db_name]}/0/foo.txt",
query: %{:rev => rev},
body: "This is a no bas64 encoded text",
headers: ["Content-Type": "text/plain;charset=utf-8"]
@@ -155,7 +159,8 @@ defmodule WithQuorumTest do
rev = resp.body["rev"]
resp =
- Couch.put("/#{context[:db_name]}/0/foo.txt",
+ Couch.put(
+ "/#{context[:db_name]}/0/foo.txt",
query: %{:rev => rev, :w => 3},
body: "This is a no bas64 encoded text",
headers: ["Content-Type": "text/plain;charset=utf-8"]
@@ -167,7 +172,8 @@ defmodule WithQuorumTest do
rev = resp.body["rev"]
resp =
- Couch.delete("/#{context[:db_name]}/0/foo.txt",
+ Couch.delete(
+ "/#{context[:db_name]}/0/foo.txt",
query: %{:rev => rev, :w => 3}
)
diff --git a/test/elixir/test/cluster_without_quorum_test.exs
b/test/elixir/test/cluster_without_quorum_test.exs
index a0bdcc37aa..4eee1e05a6 100644
--- a/test/elixir/test/cluster_without_quorum_test.exs
+++ b/test/elixir/test/cluster_without_quorum_test.exs
@@ -50,7 +50,8 @@ defmodule WithoutQuorumTest do
Couch.put("/#{db_name}")
resp =
- Couch.post("/#{context[:db_name]}",
+ Couch.post(
+ "/#{context[:db_name]}",
query: %{:w => 1},
body: %{:_id => "0", :a => 1}
)
@@ -62,7 +63,8 @@ defmodule WithoutQuorumTest do
rev = resp.body["_rev"]
resp =
- Couch.put("/#{context[:db_name]}/0",
+ Couch.put(
+ "/#{context[:db_name]}/0",
query: %{:w => 1},
body: %{:_id => "0", :_rev => rev, :a => 2}
)
@@ -84,7 +86,8 @@ defmodule WithoutQuorumTest do
db_name = context[:db_name]
Couch.put("/#{db_name}")
- Couch.post("/#{context[:db_name]}",
+ Couch.post(
+ "/#{context[:db_name]}",
body: %{:_id => "0", :a => 1}
)
@@ -129,7 +132,8 @@ defmodule WithoutQuorumTest do
rev = resp.body["rev"]
resp =
- Couch.put("/#{context[:db_name]}/0/foo.txt",
+ Couch.put(
+ "/#{context[:db_name]}/0/foo.txt",
query: %{:rev => rev},
body: "This is a no bas64 encoded text",
headers: ["Content-Type": "text/plain;charset=utf-8"]
@@ -154,7 +158,8 @@ defmodule WithoutQuorumTest do
rev = resp.body["rev"]
resp =
- Couch.put("/#{context[:db_name]}/0/foo.txt",
+ Couch.put(
+ "/#{context[:db_name]}/0/foo.txt",
query: %{:rev => rev, :w => 1},
body: "This is a no bas64 encoded text",
headers: ["Content-Type": "text/plain;charset=utf-8"]
@@ -166,7 +171,8 @@ defmodule WithoutQuorumTest do
rev = resp.body["rev"]
resp =
- Couch.delete("/#{context[:db_name]}/0/foo.txt",
+ Couch.delete(
+ "/#{context[:db_name]}/0/foo.txt",
query: %{:rev => rev, :w => 1}
)
diff --git a/test/elixir/test/rewrite_test.exs
b/test/elixir/test/rewrite_test.exs
index 250eb53d76..51acc8bba5 100644
--- a/test/elixir/test/rewrite_test.exs
+++ b/test/elixir/test/rewrite_test.exs
@@ -285,12 +285,14 @@ defmodule RewriteTest do
assert Couch.put("/#{db_name}/_design/test", body: ddoc).body["ok"]
- assert Couch.post("/#{db_name}/_bulk_docs",
+ assert Couch.post(
+ "/#{db_name}/_bulk_docs",
body: %{:docs => docs1},
query: %{w: 3}
).status_code == 201
- assert Couch.post("/#{db_name}/_bulk_docs",
+ assert Couch.post(
+ "/#{db_name}/_bulk_docs",
body: %{:docs => docs2},
query: %{w: 3}
).status_code == 201
diff --git a/test/elixir/test/security_validation_test.exs
b/test/elixir/test/security_validation_test.exs
index 5f4ddba8c2..56c4ec31b8 100644
--- a/test/elixir/test/security_validation_test.exs
+++ b/test/elixir/test/security_validation_test.exs
@@ -130,7 +130,8 @@ defmodule SecurityValidationTest do
headers = @auth_headers[:tom]
# attempt to save doc in replication context, eg ?new_edits=false
resp =
- Couch.put("/#{db_name}/#{ddoc[:_id]}",
+ Couch.put(
+ "/#{db_name}/#{ddoc[:_id]}",
body: ddoc,
headers: headers,
query: %{new_edits: false}
@@ -164,7 +165,8 @@ defmodule SecurityValidationTest do
assert resp.body["reason"] == "Documents must have an author field"
# Jerry can write the document
- assert Couch.put("/#{db_name}/test_doc",
+ assert Couch.put(
+ "/#{db_name}/test_doc",
body: %{foo: 1, author: "jerry"},
headers: jerry
).body["ok"]
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services