This is an automated email from the ASF dual-hosted git repository. wohali pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/master by this push: new f4195a0 Migrate cluster with(out) quorum js tests as elixir tests (#1812) f4195a0 is described below commit f4195a0fa2a8e90c34931e383376eb365c6ea65f Author: Juanjo Rodriguez <jjrod...@gmail.com> AuthorDate: Thu Dec 20 04:10:04 2018 +0100 Migrate cluster with(out) quorum js tests as elixir tests (#1812) --- Makefile | 14 +- Makefile.win | 14 +- test/elixir/test/cluster_with_quorum_test.exs | 179 +++++++++++++++++++++++ test/elixir/test/cluster_without_quorum_test.exs | 178 ++++++++++++++++++++++ 4 files changed, 383 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 04c40e7..c6cdcc3 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 0ffbfa9..fd1ab9b 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 0000000..76fc9b4 --- /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 0000000..a0bdcc3 --- /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