You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2016/10/20 16:45:46 UTC

[3/4] couch-mrview commit: updated refs/heads/master to 853c608

Implement recompact unit tests


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/34214630
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/34214630
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/34214630

Branch: refs/heads/master
Commit: 342146305fbe7dbd35b655b6f704e6b60a3b679c
Parents: 0d382f5
Author: Jay Doane <ja...@gmail.com>
Authored: Sat Oct 15 19:28:35 2016 -0700
Committer: Jay Doane <ja...@gmail.com>
Committed: Sat Oct 15 19:28:35 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_compactor.erl | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/34214630/src/couch_mrview_compactor.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_compactor.erl b/src/couch_mrview_compactor.erl
index 50e7eae..e343ac8 100644
--- a/src/couch_mrview_compactor.erl
+++ b/src/couch_mrview_compactor.erl
@@ -291,3 +291,39 @@ swap_compacted(OldState, NewState) ->
     erlang:demonitor(OldState#mrst.fd_monitor, [flush]),
     
     {ok, NewState#mrst{fd_monitor=Ref}}.
+
+
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+
+recompact_test_() ->
+    [
+        recompact_success_after_progress(),
+        recompact_exceeded_retry_count()
+    ].
+
+recompact_success_after_progress() ->
+    ?_test(begin
+        ok = meck:expect(couch_index_updater, update, fun
+            (Pid, _, #mrst{update_seq=0} = State) ->
+                Pid ! {'$gen_cast', {new_state, State#mrst{update_seq=1}}};
+            (_, _, State) ->
+                exit({updated, self(), State})
+        end),
+        State = #mrst{fd=self(), update_seq=0},
+        ?assertEqual({ok, State#mrst{update_seq=1}}, recompact(State)),
+        meck:unload(couch_index_updater)
+    end).
+
+recompact_exceeded_retry_count() ->
+    ?_test(begin
+        ok = meck:expect(couch_index_updater, update,
+            fun(_, _, _) ->
+                exit(error)
+        end),
+        State = #mrst{fd=self()},
+        ?assertError(exceeded_recompact_retry_count, recompact(State)),
+        meck:unload(couch_index_updater)
+    end).
+
+-endif.