eiri closed pull request #1796: Port delayed_commits test to Elixir
URL: https://github.com/apache/couchdb/pull/1796
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/README.md b/test/elixir/README.md
index e80df1f315..54de359295 100644
--- a/test/elixir/README.md
+++ b/test/elixir/README.md
@@ -33,7 +33,7 @@ X means done, - means partially
- [ ] Port conflicts.js
- [ ] Port cookie_auth.js
- [ ] Port copy_doc.js
- - [ ] Port delayed_commits.js
+ - [X] Port delayed_commits.js
- [ ] Port design_docs.js
- [ ] Port design_options.js
- [ ] Port design_paths.js
diff --git a/test/elixir/lib/couch.ex b/test/elixir/lib/couch.ex
index 302b8276ad..9342622165 100644
--- a/test/elixir/lib/couch.ex
+++ b/test/elixir/lib/couch.ex
@@ -50,6 +50,10 @@ defmodule Couch do
CouchDB library to power test suite.
"""
+ def process_url("http://" <> _ = url) do
+ url
+ end
+
def process_url(url) do
"http://127.0.0.1:15984" <> url
end
diff --git a/test/elixir/lib/couch/db_test.ex b/test/elixir/lib/couch/db_test.ex
index 930090b51b..3bbfb7eaad 100644
--- a/test/elixir/lib/couch/db_test.ex
+++ b/test/elixir/lib/couch/db_test.ex
@@ -239,4 +239,57 @@ defmodule Couch.DBTest do
opts = [pretty: true, width: 20, limit: :infinity, printable_limit:
:infinity]
inspect(resp, opts)
end
+
+ def restart_cluster() do
+ resp = Couch.get("/_membership")
+ assert resp.status_code == 200
+ nodes = resp.body["all_nodes"]
+
+ nodes_ports =
+ Enum.reduce(nodes, [], fn node, acc ->
+ port = node_to_port(node)
+ [{node, port} | acc]
+ end)
+
+ tasks =
+ Enum.map(nodes_ports, fn {node, port} ->
+ Task.async(fn -> restart_node(node, port) end)
+ end)
+
+ Task.yield_many(tasks, length(nodes) * 5000)
+ end
+
+ def restart_node(node \\ "[email protected]") do
+ port = node_to_port(node)
+ restart_node(node, port)
+ end
+
+ defp restart_node(node, port) do
+ url = "http://127.0.0.1:#{port}/_node/#{node}/_restart"
+ resp = Couch.post(url)
+ assert HTTPotion.Response.success?(resp)
+ assert resp.body["ok"]
+ # make sure node went down. we assuming the node can't bounce quick
+ # enough to inroduce a race here
+ retry_until(fn -> !node_is_running(port) end)
+ # wait utill node is back
+ retry_until(fn -> node_is_running(port) end, 500, 10_000)
+ end
+
+ defp node_is_running(port) do
+ url = "http://127.0.0.1:#{port}/_up"
+ resp = Couch.get(url)
+
+ case HTTPotion.Response.success?(resp) do
+ true -> resp.status_code in 200..399
+ false -> false
+ end
+ end
+
+ defp node_to_port(node) do
+ url = "/_node/#{node}/_config/chttpd/port"
+ resp = Couch.get(url)
+ assert HTTPotion.Response.success?(resp)
+ resp.body
+ end
end
diff --git a/test/elixir/test/delayed_commits_test.exs
b/test/elixir/test/delayed_commits_test.exs
new file mode 100644
index 0000000000..e80d0bdfb2
--- /dev/null
+++ b/test/elixir/test/delayed_commits_test.exs
@@ -0,0 +1,31 @@
+defmodule DelayedCommitsTest do
+ use CouchTestCase
+
+ @moduledoc """
+ Test CouchDB delayed commits
+ This is a port of the delayed_commits.js suite
+
+ Note that delayed_commits is deprecated in 2.0, so this is a minimal
+ test to show it still works. delayed_commits will be removed in 3.0.
+ """
+
+ @tag config: [
+ {"couchdb", "delayed_commits", "true"}
+ ]
+ @tag :with_db
+ test "delayed commit", context do
+ db_name = context[:db_name]
+ doc_id = "doc-1"
+ resp = Couch.put("/#{db_name}/#{doc_id}", body: %{a: 2, b: 4})
+ assert resp.status_code in 201..204
+ assert resp.body["ok"]
+
+ resp = Couch.get("/#{db_name}/#{doc_id}")
+ assert resp.status_code == 200, "The new doc should be in the database"
+
+ restart_cluster()
+
+ resp = Couch.get("/#{db_name}/#{doc_id}")
+ assert resp.status_code == 404, "The new doc should be missing"
+ end
+end
----------------------------------------------------------------
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