couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject [couchdb] branch master updated: Fix broken eunit test in changes_since_test_ test suite
Date Fri, 09 Jun 2017 12:06:53 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new f6321df  Fix broken eunit test in changes_since_test_ test suite
f6321df is described below

commit f6321df8ad231451181845b7523ba791780dc747
Author: jiangphcn <jiangph@cn.ibm.com>
AuthorDate: Wed May 3 16:40:33 2017 +0800

    Fix broken eunit test in changes_since_test_ test suite
    
    COUCHDB-3360/FB 85485
---
 src/couch_mrview/src/couch_mrview_test_util.erl    |  33 ++---
 src/couch_mrview/src/couch_mrview_util.erl         |   6 +-
 .../test/couch_mrview_changes_since_tests.erl      | 140 ++++++++++++++-------
 3 files changed, 112 insertions(+), 67 deletions(-)

diff --git a/src/couch_mrview/src/couch_mrview_test_util.erl b/src/couch_mrview/src/couch_mrview_test_util.erl
index 2e0cb79..b07b076 100644
--- a/src/couch_mrview/src/couch_mrview_test_util.erl
+++ b/src/couch_mrview/src/couch_mrview_test_util.erl
@@ -49,26 +49,27 @@ make_docs(local, Count) ->
 make_docs(_, Count) ->
     [doc(I) || I <- lists:seq(1, Count)].
 
-ddoc(changes) ->
+ddoc({changes, Opts}) ->
+    ViewOpts = case Opts of
+        seq_indexed ->
+            [{<<"seq_indexed">>, true}];
+        keyseq_indexed ->
+            [{<<"keyseq_indexed">>, true}];
+        seq_indexed_keyseq_indexed ->
+            [
+                {<<"seq_indexed">>, true},
+                {<<"keyseq_indexed">>, true}
+            ]
+    end,
     couch_doc:from_json_obj({[
         {<<"_id">>, <<"_design/bar">>},
-        {<<"options">>, {[
-            {<<"seq_indexed">>, true}
-        ]}},
+        {<<"options">>, {ViewOpts}},
         {<<"views">>, {[
             {<<"baz">>, {[
-                {<<"map">>, <<"function(doc) {emit(doc.val, doc.val);}">>}
-            ]}},
-            {<<"bing">>, {[
-                {<<"map">>, <<"function(doc) {}">>}
-            ]}},
-            {<<"zing">>, {[
-                {<<"map">>, <<
-                    "function(doc) {\n"
-                    "  if(doc.foo !== undefined)\n"
-                    "    emit(doc.foo, 0);\n"
-                    "}"
-                >>}
+                {
+                    <<"map">>,
+                    <<"function(doc) {emit(doc.val.toString(), doc.val);}">>
+                }
             ]}}
         ]}}
     ]});
diff --git a/src/couch_mrview/src/couch_mrview_util.erl b/src/couch_mrview/src/couch_mrview_util.erl
index 6bb8d07..a8462a2 100644
--- a/src/couch_mrview/src/couch_mrview_util.erl
+++ b/src/couch_mrview/src/couch_mrview_util.erl
@@ -366,7 +366,7 @@ get_view_changes_count(View) ->
             {ok, 0};
         {#btree{}, nil} ->
             couch_btree:fold_reduce(SBtree, CountFun, 0, []);
-        {nil, #btree{}} ->
+        {_, #btree{}} ->
             couch_btree:fold_reduce(KSBtree, CountFun, 0, [])
     end,
     case {SBtree, KSBtree} of
@@ -836,9 +836,9 @@ changes_expand_dups([{{[Key, Seq], DocId}, {dups, Vals}} | Rest], Acc)
->
 changes_expand_dups([{{Seq, Key}, {DocId, {dups, Vals}}} | Rest], Acc) ->
     Expanded = [{{Seq, Key, DocId}, Val} || Val <- Vals],
     changes_expand_dups(Rest, Expanded ++ Acc);
-changes_expand_dups([{{[Key, Seq], DocId}, Val} | Rest], Acc) ->
+changes_expand_dups([{{[Key, Seq], DocId}, {Val, _}} | Rest], Acc) ->
     changes_expand_dups(Rest, [{{Seq, Key, DocId}, Val} | Acc]);
-changes_expand_dups([{{Seq, Key}, {DocId, Val}} | Rest], Acc) ->
+changes_expand_dups([{{Seq, Key}, {DocId, Val, _}} | Rest], Acc) ->
     changes_expand_dups(Rest, [{{Seq, Key, DocId}, Val} | Acc]).
 
 maybe_load_doc(_Db, _DI, #mrargs{include_docs=false}) ->
diff --git a/src/couch_mrview/test/couch_mrview_changes_since_tests.erl b/src/couch_mrview/test/couch_mrview_changes_since_tests.erl
index 8b11e3d..1e31b39 100644
--- a/src/couch_mrview/test/couch_mrview_changes_since_tests.erl
+++ b/src/couch_mrview/test/couch_mrview_changes_since_tests.erl
@@ -17,19 +17,12 @@
 
 -define(TIMEOUT, 1000).
 
-
-
-setup() ->
-    {ok, Db} = couch_mrview_test_util:init_db(?tempdb(), changes),
-    Db.
-
 teardown(Db) ->
     couch_db:close(Db),
     couch_server:delete(Db#db.name, [?ADMIN_CTX]),
     ok.
 
-
-changes_since_test() ->
+changes_since_basic_test_() ->
     {
         "changes_since tests",
         {
@@ -37,17 +30,62 @@ changes_since_test() ->
             fun test_util:start_couch/0, fun test_util:stop_couch/1,
             {
                 foreach,
-                fun setup/0, fun teardown/1,
+                fun() ->
+                    Type = {changes, seq_indexed},
+                    {ok, Db} = couch_mrview_test_util:init_db(?tempdb(), Type),
+                    Db
+                end,
+                fun teardown/1,
                 [
                     fun test_basic/1,
-                    fun test_range/1,
                     fun test_basic_since/1,
-                    fun test_range_since/1,
                     fun test_basic_count/1,
-                    fun test_range_count/1,
                     fun test_basic_count_since/1,
+                    fun test_compact/1
+                ]
+            }
+        }
+    }.
+
+changes_since_range_test_() ->
+    {
+        "changes_since_range tests",
+        {
+            setup,
+            fun test_util:start_couch/0, fun test_util:stop_couch/1,
+            {
+                foreach,
+                fun() ->
+                    Type = {changes, keyseq_indexed},
+                    {ok, Db} = couch_mrview_test_util:init_db(?tempdb(), Type),
+                    Db
+                end,
+                fun teardown/1,
+                [
+                    fun test_range/1,
+                    fun test_range_since/1
+                ]
+            }
+        }
+    }.
+
+changes_since_range_count_test_() ->
+    {
+        "changes_since_range_count tests",
+        {
+            setup,
+            fun test_util:start_couch/0, fun test_util:stop_couch/1,
+            {
+                foreach,
+                fun() ->
+                    Type = {changes, seq_indexed_keyseq_indexed},
+                    {ok, Db} = couch_mrview_test_util:init_db(?tempdb(), Type),
+                    Db
+                end,
+                fun teardown/1,
+                [
+                    fun test_range_count/1,
                     fun test_range_count_since/1,
-                    fun test_compact/1,
                     fun test_remove_key/1
                 ]
             }
@@ -57,46 +95,48 @@ changes_since_test() ->
 test_basic(Db) ->
     Result = run_query(Db, 0, []),
     Expect = {ok, [
-                {{2, 1, <<"1">>}, 1},
-                {{3, 10, <<"10">>}, 10},
-                {{4, 2, <<"2">>}, 2},
-                {{5, 3, <<"3">>}, 3},
-                {{6, 4, <<"4">>}, 4},
-                {{7, 5, <<"5">>}, 5},
-                {{8, 6, <<"6">>}, 6},
-                {{9, 7, <<"7">>}, 7},
-                {{10, 8, <<"8">>}, 8},
-                {{11, 9, <<"9">>}, 9}
+                {{2, <<"1">>, <<"1">>}, 1},
+                {{3, <<"10">>, <<"10">>}, 10},
+                {{4, <<"2">>, <<"2">>}, 2},
+                {{5, <<"3">>, <<"3">>}, 3},
+                {{6, <<"4">>, <<"4">>}, 4},
+                {{7, <<"5">>, <<"5">>}, 5},
+                {{8, <<"6">>, <<"6">>}, 6},
+                {{9, <<"7">>, <<"7">>}, 7},
+                {{10, <<"8">>, <<"8">>}, 8},
+                {{11, <<"9">>, <<"9">>}, 9}
     ]},
     ?_assertEqual(Result, Expect).
 
 
 test_range(Db) ->
-    Result = run_query(Db, 0, [{start_key, 3}, {end_key, 5}]),
+    Range = [{start_key, <<"3">>}, {end_key, <<"5">>}],
+    Result = run_query(Db, 0, Range),
     Expect = {ok, [
-                {{5, 3, <<"3">>}, 3},
-                {{6, 4, <<"4">>}, 4},
-                {{7, 5, <<"5">>}, 5}
+                {{5, <<"3">>, <<"3">>}, 3},
+                {{6, <<"4">>, <<"4">>}, 4},
+                {{7, <<"5">>, <<"5">>}, 5}
     ]},
     ?_assertEqual(Result, Expect).
 
 test_basic_since(Db) ->
     Result = run_query(Db, 5, []),
     Expect = {ok, [
-                {{6, 4, <<"4">>}, 4},
-                {{7, 5, <<"5">>}, 5},
-                {{8, 6, <<"6">>}, 6},
-                {{9, 7, <<"7">>}, 7},
-                {{10, 8, <<"8">>}, 8},
-                {{11, 9, <<"9">>}, 9}
+                {{6, <<"4">>, <<"4">>}, 4},
+                {{7, <<"5">>, <<"5">>}, 5},
+                {{8, <<"6">>, <<"6">>}, 6},
+                {{9, <<"7">>, <<"7">>}, 7},
+                {{10, <<"8">>, <<"8">>}, 8},
+                {{11, <<"9">>, <<"9">>}, 9}
     ]},
     ?_assertEqual(Result, Expect).
 
 test_range_since(Db) ->
-    Result = run_query(Db, 5, [{start_key, 3}, {end_key, 5}]),
+    Range = [{start_key, <<"3">>}, {end_key, <<"5">>}],
+    Result = run_query(Db, 5, Range),
     Expect = {ok, [
-                {{6, 4, <<"4">>}, 4},
-                {{7, 5, <<"5">>}, 5}
+                {{6, <<"4">>, <<"4">>}, 4},
+                {{7, <<"5">>, <<"5">>}, 5}
     ]},
     ?_assertEqual(Result, Expect).
 
@@ -105,7 +145,8 @@ test_basic_count(Db) ->
     ?_assertEqual(Result, 10).
 
 test_range_count(Db) ->
-    Result = run_count_query(Db, 0, [{start_key, 3}, {end_key, 5}]),
+    Range = [{start_key, <<"3">>}, {end_key, <<"5">>}],
+    Result = run_count_query(Db, 0, Range),
     ?_assertEqual(Result, 3).
 
 test_basic_count_since(Db) ->
@@ -113,14 +154,14 @@ test_basic_count_since(Db) ->
     ?_assertEqual(Result, 6).
 
 test_range_count_since(Db) ->
-    Result = run_count_query(Db, 5, [{start_key, 3}, {end_key, 5}]),
+    Range = [{start_key, <<"3">>}, {end_key, <<"5">>}],
+    Result = run_count_query(Db, 5, Range),
     ?_assertEqual(Result, 2).
 
 test_compact(Db) ->
     Result = couch_mrview:compact(Db, <<"_design/bar">>),
-    ?_assertEqual(Result, ok),
     Count = run_count_query(Db, 0, []),
-    ?_assertEqual(Count, 10).
+    [?_assertEqual(Result, ok), ?_assertEqual(Count, 10)].
 
 test_remove_key(Db) ->
     %% add new doc
@@ -130,13 +171,12 @@ test_remove_key(Db) ->
     {ok, _} =  couch_db:ensure_full_commit(Db),
     {ok, Db1} = couch_db:reopen(Db),
     Result = run_count_query(Db1, 0, []),
-    ?_assertEqual(Result, 11),
     %% check new view key
-    Result1 = run_query(Db1, 0, [{start_key, 11}, {end_key, 11}]),
+    Range = [{start_key, <<"11">>}, {end_key, <<"11">>}],
+    Result1 = run_query(Db1, 0, Range),
     Expect = {ok, [
-                {{12, 11, <<"11">>}, 11}
+                {{12, <<"11">>, <<"11">>}, 11}
     ]},
-    ?_assertEqual(Result1, Expect),
 
     %% delete doc
     Doc2 = couch_doc:from_json_obj({[
@@ -147,13 +187,17 @@ test_remove_key(Db) ->
     {ok, _} = couch_db:update_doc(Db1, Doc2, []),
     {ok, Db2} = couch_db:reopen(Db1),
     Result2 = run_count_query(Db2, 0, []),
-    ?_assertEqual(Result2, 11),
     %% check new view key
-    Result3 = run_query(Db2, 0, [{start_key, 11}, {end_key, 11}]),
+    Result3 = run_query(Db2, 0, Range),
     Expect2 = {ok, [
-                {{13, 11, <<"11">>}, {[{<<"_removed">>, true}]}}
+                {{13, <<"11">>, <<"11">>}, removed}
     ]},
-    ?_assertEqual(Result3, Expect2).
+    [
+        ?_assertEqual(Result, 11),
+        ?_assertEqual(Result1, Expect),
+        ?_assertEqual(Result2, 11),
+        ?_assertEqual(Result3, Expect2)
+    ].
 
 run_query(Db, Since, Opts) ->
     Fun = fun(KV, Acc) -> {ok, [KV | Acc]} end,

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <commits@couchdb.apache.org>'].

Mime
View raw message