diff options
-rw-r--r-- | test/elixir/test/concurrent_writes_test.exs | 47 | ||||
-rw-r--r-- | test/elixir/test/config/suite.elixir | 4 |
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", |