You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2020/04/23 23:22:57 UTC
[couchdb] 01/01: Add a couch_views test for multiple design
documents with the same map
This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a commit to branch add-view-test-for-multiple-design-docs
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 3baae240c9f7efe6b26cc1c2616e8a584af67a9f
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Thu Apr 23 19:22:08 2020 -0400
Add a couch_views test for multiple design documents with the same map
---
src/couch_views/test/couch_views_indexer_test.erl | 80 ++++++++++++++++++++---
1 file changed, 72 insertions(+), 8 deletions(-)
diff --git a/src/couch_views/test/couch_views_indexer_test.erl b/src/couch_views/test/couch_views_indexer_test.erl
index 54f787d..3f3bdbf 100644
--- a/src/couch_views/test/couch_views_indexer_test.erl
+++ b/src/couch_views/test/couch_views_indexer_test.erl
@@ -46,6 +46,7 @@ indexer_test_() ->
?TDEF_FE(multipe_keys_from_same_doc),
?TDEF_FE(multipe_identical_keys_from_same_doc),
?TDEF_FE(fewer_multipe_identical_keys_from_same_doc),
+ ?TDEF_FE(multiple_design_docs),
?TDEF_FE(handle_size_key_limits),
?TDEF_FE(handle_size_value_limits),
?TDEF_FE(index_autoupdater_callback),
@@ -427,6 +428,65 @@ budget_history() ->
[Result || {_Pid, {couch_rate, budget, _}, Result} <- meck:history(couch_rate)].
+multiple_design_docs(Db) ->
+ DDoc1 = create_ddoc(simple, <<"_design/bar1">>),
+ DDoc2 = create_ddoc(simple, <<"_design/bar2">>),
+
+ {ok, _} = fabric2_db:update_doc(Db, doc(0), []),
+
+ {ok, {Pos1, Rev1}} = fabric2_db:update_doc(Db, DDoc1, []),
+ ?assertEqual({ok, [row(<<"0">>, 0, 0)]}, run_query(Db, DDoc1, ?MAP_FUN1)),
+
+ {ok, {Pos2, Rev2}} = fabric2_db:update_doc(Db, DDoc2, []),
+
+ ?assertEqual({ok, [row(<<"0">>, 0, 0)]}, run_query(Db, DDoc1, ?MAP_FUN1)),
+ ?assertEqual({ok, [row(<<"0">>, 0, 0)]}, run_query(Db, DDoc2, ?MAP_FUN1)),
+
+ {ok, _} = fabric2_db:update_doc(Db, doc(1), []),
+
+ ?assertEqual({ok, [
+ row(<<"0">>, 0, 0),
+ row(<<"1">>, 1, 1)
+ ]}, run_query(Db, DDoc1, ?MAP_FUN1)),
+
+ ?assertEqual({ok, [
+ row(<<"0">>, 0, 0),
+ row(<<"1">>, 1, 1)
+ ]}, run_query(Db, DDoc2, ?MAP_FUN1)),
+
+ DDoc1Delete = DDoc1#doc{revs = {Pos1, [Rev1]}, deleted = true},
+ {ok, _} = fabric2_db:update_doc(Db, DDoc1Delete, []),
+
+ fabric2_fdb:transactional(Db, fun(TxDb) ->
+ DDocs = fabric2_db:get_design_docs(Db),
+ ok = couch_views:cleanup_indices(TxDb, DDocs)
+ end),
+
+ ?assertEqual({ok, [
+ row(<<"0">>, 0, 0),
+ row(<<"1">>, 1, 1)
+ ]}, run_query(Db, DDoc2, ?MAP_FUN1)),
+
+ {ok, _} = fabric2_db:update_doc(Db, doc(2), []),
+
+ ?assertEqual({ok, [
+ row(<<"0">>, 0, 0),
+ row(<<"1">>, 1, 1),
+ row(<<"2">>, 2, 2)
+ ]}, run_query(Db, DDoc2, ?MAP_FUN1)),
+
+ DDoc2Delete = DDoc2#doc{revs = {Pos2, [Rev2]}, deleted = true},
+ {ok, _} = fabric2_db:update_doc(Db, DDoc2Delete, []),
+
+ fabric2_fdb:transactional(Db, fun(TxDb) ->
+ DDocs = fabric2_db:get_design_docs(Db),
+ ok = couch_views:cleanup_indices(TxDb, DDocs)
+ end),
+
+ ?assertError({ddoc_deleted, _}, run_query(Db, DDoc2, ?MAP_FUN1)).
+
+
+
handle_db_recreated_when_running(Db) ->
DbName = fabric2_db:name(Db),
@@ -564,9 +624,13 @@ create_ddoc() ->
create_ddoc(simple).
-create_ddoc(simple) ->
+create_ddoc(Type) ->
+ create_ddoc(Type, <<"_design/bar">>).
+
+
+create_ddoc(simple, DocId) when is_binary(DocId) ->
couch_doc:from_json_obj({[
- {<<"_id">>, <<"_design/bar">>},
+ {<<"_id">>, DocId},
{<<"views">>, {[
{?MAP_FUN1, {[
{<<"map">>, <<"function(doc) {emit(doc.val, doc.val);}">>}
@@ -577,9 +641,9 @@ create_ddoc(simple) ->
]}}
]});
-create_ddoc(multi_emit_different) ->
+create_ddoc(multi_emit_different, DocId) when is_binary(DocId) ->
couch_doc:from_json_obj({[
- {<<"_id">>, <<"_design/bar">>},
+ {<<"_id">>, DocId},
{<<"views">>, {[
{?MAP_FUN1, {[
{<<"map">>, <<"function(doc) { "
@@ -593,9 +657,9 @@ create_ddoc(multi_emit_different) ->
]}}
]});
-create_ddoc(multi_emit_same) ->
+create_ddoc(multi_emit_same, DocId) when is_binary(DocId) ->
couch_doc:from_json_obj({[
- {<<"_id">>, <<"_design/bar">>},
+ {<<"_id">>, DocId},
{<<"views">>, {[
{?MAP_FUN1, {[
{<<"map">>, <<"function(doc) { "
@@ -612,9 +676,9 @@ create_ddoc(multi_emit_same) ->
]}}
]});
-create_ddoc(multi_emit_key_limit) ->
+create_ddoc(multi_emit_key_limit, DocId) when is_binary(DocId) ->
couch_doc:from_json_obj({[
- {<<"_id">>, <<"_design/bar">>},
+ {<<"_id">>, DocId},
{<<"views">>, {[
{?MAP_FUN1, {[
{<<"map">>, <<"function(doc) { "