You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2021/03/10 13:48:59 UTC

[couchdb] 01/01: Verify correctness with concurrent updates

This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch concurrent_write_tests
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 44fa46f7c0b1bd5752e8f7fd25ad1f282c283843
Author: Robert Newson <rn...@apache.org>
AuthorDate: Tue Mar 9 15:49:15 2021 +0000

    Verify correctness with concurrent updates
---
 test/elixir/test/concurrent_writes_test.exs | 44 +++++++++++++++++++++++++++++
 test/elixir/test/config/suite.elixir        |  4 +++
 2 files changed, 48 insertions(+)

diff --git a/test/elixir/test/concurrent_writes_test.exs b/test/elixir/test/concurrent_writes_test.exs
new file mode 100644
index 0000000..5f894c3
--- /dev/null
+++ b/test/elixir/test/concurrent_writes_test.exs
@@ -0,0 +1,44 @@
+defmodule ConcurrentWritesTest do
+  use CouchTestCase
+
+  @moduletag :concurrent_writes
+  @moduletag kind: :single_node
+
+  @moduledoc """
+  Test CouchDB under concurrent write load
+  """
+
+  @tag :with_db
+  test "Primary data tests", context do
+    db_name = context[:db_name]
+    parent = self()
+    Enum.each(1..99,
+      fn x -> spawn fn ->
+          Couch.put("/#{db_name}/doc#{x}", body: %{:a => x})
+          send parent, :done
+        end end)
+    Enum.each(1..99, fn _x -> receive do :done -> :done end end)
+    assert Couch.get("/#{db_name}").body["doc_count"] == 99
+  end
+
+  @tag :with_db
+  test "Secondary data tests", context do
+    db_name = context[:db_name]
+    map_fun = "function(doc) { emit(doc.foo); }"
+    red_fun = "_sum"
+    ddoc_id = "_design/foo"
+    ddoc = %{:views => %{:foo => %{:map => map_fun, :reduce => red_fun}}}
+    Couch.put("/#{db_name}/#{ddoc_id}", body: ddoc)
+    parent = self()
+    Enum.each(1..99,
+      fn x -> spawn fn ->
+          Couch.put("/#{db_name}/doc#{x}", body: %{:a => x})
+          send parent, :done
+        end end)
+    Enum.each(1..99, fn _x -> receive do :done -> :done end end)
+    rows = Couch.get("/#{db_name}/#{ddoc_id}/_view/foo").body["rows"]
+    result = hd(rows)["value"]
+    assert result = Enum.sum(1..99)
+  end
+
+end
diff --git a/test/elixir/test/config/suite.elixir b/test/elixir/test/config/suite.elixir
index a879182..65f972c 100644
--- a/test/elixir/test/config/suite.elixir
+++ b/test/elixir/test/config/suite.elixir
@@ -131,6 +131,10 @@
   "CompactTest": [
     "compaction reduces size of deleted docs"
   ],
+  "ConcurrentWritesTest": [
+    "Primary data tests",
+    "Secondary data tests"
+  ],
   "ConfigTest": [
     "Atoms, binaries, and strings suffice as whitelist sections and keys.",
     "Blacklist is functional",