summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuanjo Rodriguez <jjrodrig@gmail.com>2018-12-20 04:10:04 +0100
committerJoan Touzet <wohali@users.noreply.github.com>2018-12-19 22:10:04 -0500
commitf4195a0fa2a8e90c34931e383376eb365c6ea65f (patch)
tree86929fef2a304c049043c20290da834f065fff44
parent11feb2f8c14c305c50ca095c396d1c04d33505a2 (diff)
downloadcouchdb-f4195a0fa2a8e90c34931e383376eb365c6ea65f.tar.gz
Migrate cluster with(out) quorum js tests as elixir tests (#1812)
-rw-r--r--Makefile14
-rw-r--r--Makefile.win14
-rw-r--r--test/elixir/test/cluster_with_quorum_test.exs179
-rw-r--r--test/elixir/test/cluster_without_quorum_test.exs178
4 files changed, 383 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 04c40e7fe..c6cdcc350 100644
--- a/Makefile
+++ b/Makefile
@@ -201,7 +201,19 @@ python-black-update: .venv/bin/black
.PHONY: elixir
elixir: elixir-check-formatted elixir-credo devclean
- @dev/run -a adm:pass --no-eval test/elixir/run $(EXUNIT_OPTS)
+ @dev/run -a adm:pass --no-eval 'test/elixir/run --exclude without_quorum_test --exclude with_quorum_test $(EXUNIT_OPTS)'
+
+.PHONY: elixir-cluster-without-quorum
+elixir-cluster-without-quorum: elixir-check-formatted elixir-credo devclean
+ @dev/run -n 3 -q -a adm:pass \
+ --degrade-cluster 2 \
+ --no-eval 'test/elixir/run --only without_quorum_test $(EXUNIT_OPTS)'
+
+.PHONY: elixir-cluster-with-quorum
+elixir-cluster-with-quorum: elixir-check-formatted elixir-credo devclean
+ @dev/run -n 3 -q -a adm:pass \
+ --degrade-cluster 1 \
+ --no-eval 'test/elixir/run --only with_quorum_test $(EXUNIT_OPTS)'
.PHONY: elixir-check-formatted
elixir-check-formatted:
diff --git a/Makefile.win b/Makefile.win
index 0ffbfa971..fd1ab9b86 100644
--- a/Makefile.win
+++ b/Makefile.win
@@ -173,7 +173,19 @@ python-black-update: .venv/bin/black
.PHONY: elixir
elixir: elixir-check-formatted elixir-credo devclean
- @dev\run -a adm:pass --no-eval test\elixir\run.cmd $(EXUNIT_OPTS)
+ @dev\run -a adm:pass --no-eval 'test\elixir\run.cmd --exclude without_quorum_test --exclude with_quorum_test $(EXUNIT_OPTS)'
+
+.PHONY: elixir-cluster-without-quorum
+elixir-cluster-without-quorum: elixir-check-formatted elixir-credo devclean
+ @dev\run -n 3 -q -a adm:pass \
+ --degrade-cluster 2 \
+ --no-eval 'test\elixir\run --only without_quorum_test $(EXUNIT_OPTS)'
+
+.PHONY: elixir-cluster-with-quorum
+elixir-cluster-with-quorum: elixir-check-formatted elixir-credo devclean
+ @dev\run -n 3 -q -a adm:pass \
+ --degrade-cluster 1 \
+ --no-eval 'test\elixir\run --only with_quorum_test $(EXUNIT_OPTS)'
.PHONY: elixir-check-formatted
elixir-check-formatted:
diff --git a/test/elixir/test/cluster_with_quorum_test.exs b/test/elixir/test/cluster_with_quorum_test.exs
new file mode 100644
index 000000000..76fc9b449
--- /dev/null
+++ b/test/elixir/test/cluster_with_quorum_test.exs
@@ -0,0 +1,179 @@
+defmodule WithQuorumTest do
+ use CouchTestCase
+
+ @moduletag :with_quorum_test
+
+ @moduledoc """
+ Test CouchDB API in a cluster without quorum.
+ """
+ @tag :with_db_name
+ test "Creating/Deleting DB should return 201-Created/202-Acepted", context do
+ db_name = context[:db_name]
+ resp = Couch.put("/#{db_name}")
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
+ resp = Couch.delete("/#{db_name}")
+ msg = "Should return 202-Acepted"
+ assert resp.status_code == 202, msg
+ end
+
+ @tag :with_db_name
+ test "Creating-Updating/Deleting doc should return 201-Created/200-OK", context do
+ db_name = context[:db_name]
+ Couch.put("/#{db_name}")
+
+ resp = Couch.post("/#{context[:db_name]}", body: %{:_id => "0", :a => 1})
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
+
+ resp = Couch.get("/#{context[:db_name]}/0")
+ rev = resp.body["_rev"]
+
+ resp =
+ Couch.put("/#{context[:db_name]}/0", body: %{:_id => "0", :_rev => rev, :a => 2})
+
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
+
+ resp = Couch.get("/#{context[:db_name]}/0")
+ rev = resp.body["_rev"]
+ resp = Couch.delete("/#{context[:db_name]}/0", query: %{:rev => rev})
+ msg = "Should return 200-OK"
+ assert resp.status_code == 200, msg
+
+ Couch.delete("/#{db_name}")
+ end
+
+ @tag :with_db_name
+ test "Creating-Updating/Deleting doc with overriden quorum should return 202-Acepted/200-OK",
+ context do
+ db_name = context[:db_name]
+ Couch.put("/#{db_name}")
+
+ resp =
+ Couch.post("/#{context[:db_name]}",
+ query: %{:w => 3},
+ body: %{:_id => "0", :a => 1}
+ )
+
+ msg = "Should return 202-Acepted"
+ assert resp.status_code == 202, msg
+
+ resp = Couch.get("/#{context[:db_name]}/0")
+ rev = resp.body["_rev"]
+
+ resp =
+ Couch.put("/#{context[:db_name]}/0",
+ query: %{:w => 3},
+ body: %{:_id => "0", :_rev => rev, :a => 2}
+ )
+
+ msg = "Should return 202-Acepted"
+ assert resp.status_code == 202, msg
+
+ resp = Couch.get("/#{context[:db_name]}/0")
+ rev = resp.body["_rev"]
+ resp = Couch.delete("/#{context[:db_name]}/0", query: %{:w => 1, :rev => rev})
+ msg = "Should return 200-Ok"
+ assert resp.status_code == 200, msg
+
+ Couch.delete("/#{db_name}")
+ end
+
+ @tag :with_db_name
+ test "Copy doc should return 201-Created", context do
+ db_name = context[:db_name]
+ Couch.put("/#{db_name}")
+
+ Couch.post("/#{context[:db_name]}",
+ body: %{:_id => "0", :a => 1}
+ )
+
+ headers = [Destination: "1"]
+ resp = Couch.request(:copy, "/#{context[:db_name]}/0", headers: headers)
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
+ Couch.delete("/#{db_name}")
+ end
+
+ @doc_range 1..5
+
+ @tag :with_db_name
+ test "Bulk docs should return 201-Created", context do
+ db_name = context[:db_name]
+ Couch.put("/#{db_name}")
+ docs = create_docs(@doc_range)
+ resp = Couch.post("/#{db_name}/_bulk_docs", body: %{docs: docs})
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
+
+ Couch.delete("/#{db_name}")
+ end
+
+ @tag :with_db_name
+ test "Bulk docs overriden quorum should return 202-Acepted", context do
+ db_name = context[:db_name]
+ Couch.put("/#{db_name}")
+ docs = create_docs(@doc_range)
+ resp = Couch.post("/#{db_name}/_bulk_docs", query: %{:w => 3}, body: %{docs: docs})
+ msg = "Should return 202-Acepted"
+ assert resp.status_code == 202, msg
+
+ Couch.delete("/#{db_name}")
+ end
+
+ @tag :with_db_name
+ test "Attachments should return 201-Created", context do
+ db_name = context[:db_name]
+ Couch.put("/#{db_name}")
+ resp = Couch.post("/#{context[:db_name]}", body: %{:_id => "0"})
+ rev = resp.body["rev"]
+
+ resp =
+ 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"]
+ )
+
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
+
+ rev = resp.body["rev"]
+ resp = Couch.delete("/#{context[:db_name]}/0/foo.txt", query: %{:rev => rev})
+ msg = "Should return 200-Ok"
+ assert resp.status_code == 200, msg
+
+ Couch.delete("/#{db_name}")
+ end
+
+ @tag :with_db_name
+ test "Attachments overriden quorum should return 202-Acepted", context do
+ db_name = context[:db_name]
+ Couch.put("/#{db_name}")
+ resp = Couch.post("/#{context[:db_name]}", body: %{:_id => "0"})
+ rev = resp.body["rev"]
+
+ resp =
+ 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"]
+ )
+
+ msg = "Should return 202-Acepted"
+ assert resp.status_code == 202, msg
+
+ rev = resp.body["rev"]
+
+ resp =
+ Couch.delete("/#{context[:db_name]}/0/foo.txt",
+ query: %{:rev => rev, :w => 3}
+ )
+
+ msg = "Should return 200-Ok"
+ assert resp.status_code == 200, msg
+
+ Couch.delete("/#{db_name}")
+ end
+end
diff --git a/test/elixir/test/cluster_without_quorum_test.exs b/test/elixir/test/cluster_without_quorum_test.exs
new file mode 100644
index 000000000..a0bdcc37a
--- /dev/null
+++ b/test/elixir/test/cluster_without_quorum_test.exs
@@ -0,0 +1,178 @@
+defmodule WithoutQuorumTest do
+ use CouchTestCase
+
+ @moduletag :without_quorum_test
+
+ @moduledoc """
+ Test CouchDB API in a cluster without quorum.
+ """
+ @tag :with_db_name
+ test "Creating/Deleting DB should return 202-Acepted", context do
+ db_name = context[:db_name]
+ resp = Couch.put("/#{db_name}")
+ msg = "Should return 202-Acepted"
+ assert resp.status_code == 202, msg
+ resp = Couch.delete("/#{db_name}")
+ assert resp.status_code == 202, msg
+ end
+
+ @tag :with_db_name
+ test "Creating/Updating/Deleting doc should return 202-Acepted", context do
+ db_name = context[:db_name]
+ Couch.put("/#{db_name}")
+
+ resp = Couch.post("/#{context[:db_name]}", body: %{:_id => "0", :a => 1})
+ msg = "Should return 202-Acepted"
+ assert resp.status_code == 202, msg
+
+ resp = Couch.get("/#{context[:db_name]}/0")
+ rev = resp.body["_rev"]
+
+ resp =
+ Couch.put("/#{context[:db_name]}/0", body: %{:_id => "0", :_rev => rev, :a => 2})
+
+ msg = "Should return 202-Acepted"
+ assert resp.status_code == 202, msg
+
+ resp = Couch.get("/#{context[:db_name]}/0")
+ rev = resp.body["_rev"]
+ resp = Couch.delete("/#{context[:db_name]}/0", query: %{:rev => rev})
+ msg = "Should return 202-Acepted"
+ assert resp.status_code == 202, msg
+
+ Couch.delete("/#{db_name}")
+ end
+
+ @tag :with_db_name
+ test "Creating-Updating/Deleting doc with overriden quorum should return 201-Created/200-OK",
+ context do
+ db_name = context[:db_name]
+ Couch.put("/#{db_name}")
+
+ resp =
+ Couch.post("/#{context[:db_name]}",
+ query: %{:w => 1},
+ body: %{:_id => "0", :a => 1}
+ )
+
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
+
+ resp = Couch.get("/#{context[:db_name]}/0")
+ rev = resp.body["_rev"]
+
+ resp =
+ Couch.put("/#{context[:db_name]}/0",
+ query: %{:w => 1},
+ body: %{:_id => "0", :_rev => rev, :a => 2}
+ )
+
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
+
+ resp = Couch.get("/#{context[:db_name]}/0")
+ rev = resp.body["_rev"]
+ resp = Couch.delete("/#{context[:db_name]}/0", query: %{:w => 1, :rev => rev})
+ msg = "Should return 200-Ok"
+ assert resp.status_code == 200, msg
+
+ Couch.delete("/#{db_name}")
+ end
+
+ @tag :with_db_name
+ test "Copy doc should return 202-Acepted", context do
+ db_name = context[:db_name]
+ Couch.put("/#{db_name}")
+
+ Couch.post("/#{context[:db_name]}",
+ body: %{:_id => "0", :a => 1}
+ )
+
+ headers = [Destination: "1"]
+ resp = Couch.request(:copy, "/#{context[:db_name]}/0", headers: headers)
+ msg = "Should return 202-Acepted"
+ assert resp.status_code == 202, msg
+ Couch.delete("/#{db_name}")
+ end
+
+ @doc_range 1..5
+
+ @tag :with_db_name
+ test "Bulk docs should return 202-Acepted", context do
+ db_name = context[:db_name]
+ Couch.put("/#{db_name}")
+ docs = create_docs(@doc_range)
+ resp = Couch.post("/#{db_name}/_bulk_docs", body: %{docs: docs})
+ msg = "Should return 202-Acepted"
+ assert resp.status_code == 202, msg
+
+ Couch.delete("/#{db_name}")
+ end
+
+ @tag :with_db_name
+ test "Bulk docs overriden quorum should return 201-Created", context do
+ db_name = context[:db_name]
+ Couch.put("/#{db_name}")
+ docs = create_docs(@doc_range)
+ resp = Couch.post("/#{db_name}/_bulk_docs", query: %{:w => 1}, body: %{docs: docs})
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
+
+ Couch.delete("/#{db_name}")
+ end
+
+ @tag :with_db_name
+ test "Attachments should return 202-Acepted", context do
+ db_name = context[:db_name]
+ Couch.put("/#{db_name}")
+ resp = Couch.post("/#{context[:db_name]}", body: %{:_id => "0"})
+ rev = resp.body["rev"]
+
+ resp =
+ 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"]
+ )
+
+ msg = "Should return 202-Acepted"
+ assert resp.status_code == 202, msg
+
+ rev = resp.body["rev"]
+ resp = Couch.delete("/#{context[:db_name]}/0/foo.txt", query: %{:rev => rev})
+ msg = "Should return 200-Ok"
+ assert resp.status_code == 200, msg
+
+ Couch.delete("/#{db_name}")
+ end
+
+ @tag :with_db_name
+ test "Attachments overriden quorum should return 201-Created", context do
+ db_name = context[:db_name]
+ Couch.put("/#{db_name}")
+ resp = Couch.post("/#{context[:db_name]}", body: %{:_id => "0"})
+ rev = resp.body["rev"]
+
+ resp =
+ 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"]
+ )
+
+ msg = "Should return 201-Created"
+ assert resp.status_code == 201, msg
+
+ rev = resp.body["rev"]
+
+ resp =
+ Couch.delete("/#{context[:db_name]}/0/foo.txt",
+ query: %{:rev => rev, :w => 1}
+ )
+
+ msg = "Should return 200-Ok"
+ assert resp.status_code == 200, msg
+
+ Couch.delete("/#{db_name}")
+ end
+end