summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@apache.org>2021-03-09 15:49:15 +0000
committerRobert Newson <rnewson@apache.org>2021-03-10 14:18:22 +0000
commit6de3caca2162b1ee332aa7072c73d297866d5912 (patch)
treeec8386885c981fb8da13f04cff24d6e47b313553
parentfdd53774bd802fe9e6b6eb473ae5b40c7436137c (diff)
downloadcouchdb-concurrent_write_tests.tar.gz
Verify correctness with concurrent updatesconcurrent_write_tests
-rw-r--r--test/elixir/test/concurrent_writes_test.exs47
-rw-r--r--test/elixir/test/config/suite.elixir4
2 files changed, 51 insertions, 0 deletions
diff --git a/test/elixir/test/concurrent_writes_test.exs b/test/elixir/test/concurrent_writes_test.exs
new file mode 100644
index 000000000..c38fa1da0
--- /dev/null
+++ b/test/elixir/test/concurrent_writes_test.exs
@@ -0,0 +1,47 @@
+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)
+ Enum.each(1..99, fn x ->
+ assert Couch.get("/#{db_name}/doc#{x}").body["a"] == x
+ 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(null, doc.a); }"
+ 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 a87918246..65f972c2f 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",