summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuanjo Rodriguez <juanjo@apache.org>2020-06-29 18:02:39 +0200
committerJuanjo Rodriguez <jjrodrig@gmail.com>2020-06-30 13:17:33 +0200
commiteaf6e744bf286cdca8b07ea63303dd3920bcff2a (patch)
tree8a1c1422535343cd84b4bd85450151ea8017791f
parentc6940d857d86c83c1aa69f068b1c503428b7b6e8 (diff)
downloadcouchdb-eaf6e744bf286cdca8b07ea63303dd3920bcff2a.tar.gz
Port view_update_seq.js into elixir
-rw-r--r--test/elixir/lib/couch/db_test.ex2
-rw-r--r--test/elixir/test/view_update_seq_test.exs142
-rw-r--r--test/javascript/tests/view_update_seq.js1
3 files changed, 144 insertions, 1 deletions
diff --git a/test/elixir/lib/couch/db_test.ex b/test/elixir/lib/couch/db_test.ex
index a61db1424..23f10937d 100644
--- a/test/elixir/lib/couch/db_test.ex
+++ b/test/elixir/lib/couch/db_test.ex
@@ -341,7 +341,7 @@ defmodule Couch.DBTest do
Couch.get("/#{db_name}/_design/#{view_root}/_view/#{view_name}", query: options)
_ ->
- Couch.post("/#{db_name}/_design/#{view_root}/_view/#{view_name}",
+ Couch.post("/#{db_name}/_design/#{view_root}/_view/#{view_name}", query: options,
body: %{"keys" => keys}
)
end
diff --git a/test/elixir/test/view_update_seq_test.exs b/test/elixir/test/view_update_seq_test.exs
new file mode 100644
index 000000000..38b42c7a7
--- /dev/null
+++ b/test/elixir/test/view_update_seq_test.exs
@@ -0,0 +1,142 @@
+defmodule ViewUpdateSeqTest do
+ use CouchTestCase
+
+ @moduletag :view_update_seq
+
+ @moduledoc """
+ This is a port of the view_update_seq.js test suite.
+ """
+
+ @design_doc %{
+ _id: "_design/test",
+ language: "javascript",
+ autoupdate: false,
+ views: %{
+ all_docs: %{
+ map: "function(doc) { emit(doc.integer, doc.string) }"
+ },
+ summate: %{
+ map:
+ "function (doc) { if (typeof doc.integer === 'number') { emit(doc.integer, doc.integer)}; }",
+ reduce: "function (keys, values) { return sum(values); };"
+ }
+ }
+ }
+
+ defp seq_int(seq) do
+ {int, _} =
+ seq
+ |> String.split("-")
+ |> Enum.at(0)
+ |> Integer.parse()
+
+ int
+ end
+
+ @tag :with_db
+ test "db info update seq", context do
+ db_name = context[:db_name]
+
+ info = info(db_name)
+ assert seq_int(info["update_seq"]) == 0
+
+ create_doc(db_name, @design_doc)
+
+ info = info(db_name)
+ assert seq_int(info["update_seq"]) == 1
+ end
+
+ @tag :with_db
+ test "_all_docs update seq", context do
+ db_name = context[:db_name]
+
+ resp = Couch.get("/#{db_name}/_all_docs", query: %{:update_seq => true})
+ assert seq_int(resp.body["update_seq"]) == 0
+
+ create_doc(db_name, @design_doc)
+
+ resp = Couch.get("/#{db_name}/_all_docs", query: %{:update_seq => true})
+ assert length(resp.body["rows"]) == 1
+ assert seq_int(resp.body["update_seq"]) == 1
+
+ docs = make_docs(0..99)
+ bulk_save(db_name, docs)
+
+ resp = Couch.get("/#{db_name}/_all_docs", query: %{:limit => 1})
+ assert length(resp.body["rows"]) == 1
+ assert Map.has_key?(resp.body, "update_seq") == false
+
+ resp = Couch.get("/#{db_name}/_all_docs", query: %{:limit => 1, :update_seq => true})
+ assert length(resp.body["rows"]) == 1
+ assert seq_int(resp.body["update_seq"]) == 101
+ end
+
+ @tag :with_db
+ test "view update seq", context do
+ db_name = context[:db_name]
+
+ create_doc(db_name, @design_doc)
+ docs = make_docs(0..99)
+ bulk_save(db_name, docs)
+
+ resp = view(db_name, "test/all_docs", %{:limit => 1, :update_seq => true})
+ assert length(resp.body["rows"]) == 1
+ assert seq_int(resp.body["update_seq"]) == 101
+
+ resp = view(db_name, "test/all_docs", %{:limit => 1, :update_seq => false})
+ assert length(resp.body["rows"]) == 1
+ assert Map.has_key?(resp.body, "update_seq") == false
+
+ resp = view(db_name, "test/summate", %{:update_seq => true})
+ assert length(resp.body["rows"]) == 1
+ assert seq_int(resp.body["update_seq"]) == 101
+
+ save(db_name, %{"_id" => "A", "integer" => 1})
+
+ resp =
+ view(db_name, "test/all_docs", %{:limit => 1, :stale => "ok", :update_seq => true})
+
+ assert length(resp.body["rows"]) == 1
+ assert seq_int(resp.body["update_seq"]) == 101
+
+ save(db_name, %{"_id" => "AA", "integer" => 2})
+
+ resp =
+ view(db_name, "test/all_docs", %{
+ :limit => 1,
+ :stale => "update_after",
+ :update_seq => true
+ })
+
+ assert length(resp.body["rows"]) == 1
+ assert seq_int(resp.body["update_seq"]) == 101
+
+ retry_until(fn ->
+ resp =
+ view(db_name, "test/all_docs", %{:limit => 1, :stale => "ok", :update_seq => true})
+
+ assert length(resp.body["rows"]) == 1
+ seq_int(resp.body["update_seq"]) == 103
+ end)
+
+ resp =
+ view(db_name, "test/all_docs", %{:limit => 1, :stale => "ok", :update_seq => true})
+
+ assert length(resp.body["rows"]) == 1
+ assert seq_int(resp.body["update_seq"]) == 103
+
+ resp = view(db_name, "test/all_docs", %{:limit => 1, :update_seq => true})
+
+ assert length(resp.body["rows"]) == 1
+ assert seq_int(resp.body["update_seq"]) == 103
+
+ resp = view(db_name, "test/all_docs", %{:update_seq => true}, ["0", "1"])
+ assert seq_int(resp.body["update_seq"]) == 103
+
+ resp = view(db_name, "test/all_docs", %{:update_seq => true}, ["0", "1"])
+ assert seq_int(resp.body["update_seq"]) == 103
+
+ resp = view(db_name, "test/summate", %{:group => true, :update_seq => true}, [0, 1])
+ assert seq_int(resp.body["update_seq"]) == 103
+ end
+end
diff --git a/test/javascript/tests/view_update_seq.js b/test/javascript/tests/view_update_seq.js
index c14453f05..8b3a3fb84 100644
--- a/test/javascript/tests/view_update_seq.js
+++ b/test/javascript/tests/view_update_seq.js
@@ -10,6 +10,7 @@
// License for the specific language governing permissions and limitations under
// the License.
+couchTests.elixir = true;
couchTests.view_update_seq = function(debug) {
var db_name = get_random_db_name();
var db = new CouchDB(db_name, {"X-Couch-Full-Commit":"false"});