You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/11/26 14:17:41 UTC

[GitHub] garrensmith closed pull request #1738: test: port lots_of_docs.js to Elixir test suite

garrensmith closed pull request #1738: test: port lots_of_docs.js to Elixir test suite
URL: https://github.com/apache/couchdb/pull/1738
 
 
   

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 b1b745af30..48f936fcbd 100644
--- a/test/elixir/README.md
+++ b/test/elixir/README.md
@@ -48,7 +48,7 @@ X means done, - means partially
   - [ ] Port list_views.js
   - [ ] Port lorem_b64.txt
   - [ ] Port lorem.txt
-  - [ ] Port lots_of_docs.js
+  - [X] Port lots_of_docs.js
   - [ ] Port method_override.js
   - [ ] Port multiple_rows.js
   - [ ] Port proxyauth.js
diff --git a/test/elixir/test/lots_of_docs_test.exs b/test/elixir/test/lots_of_docs_test.exs
new file mode 100644
index 0000000000..4115f1c78e
--- /dev/null
+++ b/test/elixir/test/lots_of_docs_test.exs
@@ -0,0 +1,95 @@
+defmodule LotsOfDocsTest do
+    use CouchTestCase
+    
+    @moduletag :lots_of_docs
+    @docs_range 0..499
+
+    @moduledoc """
+    Test saving a semi-large quanitity of documents and do some view queries.
+    This is a port of the lots_of_docs.js suite
+    """
+
+    @tag :with_db
+    test "lots of docs with _all_docs", context do
+        db_name = context[:db_name]
+        @docs_range
+            |> create_docs()
+            |> Enum.chunk_every(100)
+            |> Enum.each(fn(docs) -> bulk_post(docs, db_name) end)
+
+        %{"rows" => rows, "total_rows" => total_rows} = Couch.get("/#{db_name}/_all_docs").body
+        assert total_rows === Enum.count(@docs_range)
+        assert total_rows === Enum.count(rows)
+        @docs_range
+            |> Enum.map(fn(i) -> Integer.to_string(i) end)
+            |> Enum.sort()
+            |> Enum.with_index()
+            |> Enum.each(fn({value, index}) ->
+                assert Map.fetch!(Enum.at(rows, index), "key") === value
+            end)
+
+        %{"rows" => desc_rows, "total_rows" => desc_total_rows} = Couch.get(
+            "/#{db_name}/_all_docs",
+            query: %{:descending => true}
+        ).body
+        assert desc_total_rows === Enum.count(@docs_range)
+        assert desc_total_rows === Enum.count(desc_rows)
+        @docs_range
+            |> Enum.map(fn(i) -> Integer.to_string(i) end)
+            |> Enum.sort()
+            |> Enum.reverse()
+            |> Enum.with_index()
+            |> Enum.each(fn({value, index}) ->
+                assert Map.fetch!(Enum.at(desc_rows, index), "key") === value
+            end)
+    end
+
+    @tag :with_db
+    test "lots of docs with a regular view", context do
+        db_name = context[:db_name]
+        @docs_range
+            |> create_docs()
+            |> Enum.chunk_every(100)
+            |> Enum.each(fn(docs) -> bulk_post(docs, db_name) end)
+
+        %{"rows" => rows, "total_rows" => total_rows} = query_view(db_name)
+        assert total_rows === Enum.count(rows)
+        assert total_rows === Enum.count(@docs_range)
+        Enum.each(@docs_range, fn(i) ->
+            assert Map.fetch!(Enum.at(rows, i), "key") === i
+        end)
+
+        %{"rows" => desc_rows, "total_rows" => desc_total_rows} = query_view(db_name, "descending")
+        assert desc_total_rows === Enum.count(desc_rows)
+        assert desc_total_rows === Enum.count(@docs_range)
+        @docs_range
+            |> Enum.reverse()
+            |> Enum.with_index()
+            |> Enum.each(fn({value, index}) ->
+                assert Map.fetch!(Enum.at(desc_rows, index), "key") === value
+            end)
+    end
+
+    defp query_view(db_name, sorting \\ "ascending") do
+        descending = if(sorting === "descending", do: true, else: false)
+        map_fun = "function(doc) { emit(doc.integer, null); }"
+        map_doc = %{:views => %{:view => %{:map => map_fun}}}
+        %{"rev" => rev} = Couch.put("/#{db_name}/_design/tempddoc", body: map_doc).body
+        response = Couch.get(
+            "/#{db_name}/_design/tempddoc/_view/view",
+            query: %{:descending => descending}
+        ).body
+        Couch.delete("/#{db_name}/_design/tempddoc?rev=#{rev}")
+        response
+    end
+
+    defp bulk_post(docs, db) do
+        resp = Couch.post("/#{db}/_bulk_docs", [body: %{docs: docs}])
+        assert resp.status_code == 201 and length(resp.body) == length(docs),
+        """
+        Expected 201 and the same number of response rows as in request, but got
+        #{pretty_inspect resp}
+        """
+        resp
+  end
+end
\ No newline at end of file


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services