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

davisp pushed a commit to branch fix-view-row-bug
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit dc7382fa11a64fc4b63d19cc4ba95d313340d8a7
Author: Paul J. Davis <paul.joseph.da...@gmail.com>
AuthorDate: Fri Feb 26 13:08:42 2021 -0600

    Add failing cases for ebtree:lookup_multi/3 bug
    
    These two test cases expose the subtle bug in ebtree:lookup_multi/3
    where a key that doesn't exist in the tree can prevent a subsequent
    lookup key from matching in the same KV node.
---
 src/couch_views/test/couch_views_indexer_test.erl | 27 +++++++++++++++++++++++
 src/ebtree/src/ebtree.erl                         |  3 ++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/couch_views/test/couch_views_indexer_test.erl 
b/src/couch_views/test/couch_views_indexer_test.erl
index e18c007..09493db 100644
--- a/src/couch_views/test/couch_views_indexer_test.erl
+++ b/src/couch_views/test/couch_views_indexer_test.erl
@@ -47,6 +47,7 @@ indexer_test_() ->
                     ?TDEF_FE(multiple_identical_keys_from_same_doc),
                     ?TDEF_FE(fewer_multiple_identical_keys_from_same_doc),
                     ?TDEF_FE(multiple_design_docs),
+                    ?TDEF_FE(multiple_doc_update_with_existing_rows),
                     ?TDEF_FE(handle_size_key_limits),
                     ?TDEF_FE(handle_size_value_limits),
                     ?TDEF_FE(index_autoupdater_callback),
@@ -424,6 +425,32 @@ multiple_design_docs(Db) ->
     ?assertError({ddoc_deleted, _}, run_query(Db, DDoc2, ?MAP_FUN1)).
 
 
+multiple_doc_update_with_existing_rows(Db) ->
+    couch_log:error("START TEST", []),
+    DDoc = create_ddoc(),
+    Doc0 = doc(0),
+    Doc1 = doc(1),
+
+    {ok, _} = fabric2_db:update_doc(Db, DDoc, []),
+    {ok, {Pos, Rev}} = fabric2_db:update_doc(Db, Doc1, []),
+
+    {ok, Out1} = run_query(Db, DDoc, ?MAP_FUN1),
+
+    ?assertEqual([row(<<"1">>, 1, 1)], Out1),
+
+    Doc2 = Doc1#doc{
+        revs = {Pos, [Rev]},
+        body = {[{<<"val">>, 2}]}
+    },
+    {ok, _} = fabric2_db:update_docs(Db, [Doc0, Doc2], []),
+
+    {ok, Out2} = run_query(Db, DDoc, ?MAP_FUN1),
+
+    ?assertEqual([
+        row(<<"0">>, 0, 0),
+        row(<<"1">>, 2, 2)
+    ], Out2).    
+
 handle_db_recreated_when_running(Db) ->
     DbName = fabric2_db:name(Db),
 
diff --git a/src/ebtree/src/ebtree.erl b/src/ebtree/src/ebtree.erl
index 1a65c9a..bbb0ca8 100644
--- a/src/ebtree/src/ebtree.erl
+++ b/src/ebtree/src/ebtree.erl
@@ -1394,7 +1394,8 @@ lookup_multi_test() ->
     validate_tree(Db, Tree),
     ?assertEqual([{1, 2}], lookup_multi(Db, Tree, [1])),
     ?assertEqual([{15, 16}, {2, 3}], lookup_multi(Db, Tree, [2, 15])),
-    ?assertEqual([{15, 16}, {4, 5}, {2, 3}], lookup_multi(Db, Tree, [2, 101, 
15, 4, -3])).
+    ?assertEqual([{15, 16}, {4, 5}, {2, 3}], lookup_multi(Db, Tree, [2, 101, 
15, 4, -3])),
+    ?assertEqual([{2, 3}], lookup_multi(Db, Tree, [1.5, 2])).
 
 
 insert_multi_test() ->

Reply via email to