Fix unit tests in couch_mrview_compactor
This fixes the two tests that are in couch_mrview_compactor.erl. For
some reason they don't always run in CI or even for local `make check`
runs. However when they do run they fail as they don't account for how
couch_index_updater:update/3 works and don't start couch_log.
The theory for why these don't always run is related to how meck loads
modules. I'm told that these should probably be moved to
test/couch_mrview_compactor_tests.erl but then that would remove access
to the recompact/1 function. For now I'll leave them here I guess and if
they do ever run they'll not break the build now.
diff --git a/src/couch_mrview_compactor.erl b/src/couch_mrview_compactor.erl
index 5957908..9ef79b6 100644
--- a/src/couch_mrview_compactor.erl
+++ b/src/couch_mrview_compactor.erl
@@ -307,13 +307,16 @@
?_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})
+ Pid ! {'$gen_cast', {new_state, State#mrst{update_seq = 1}}},
+ timer:sleep(100),
+ exit({updated, self(), State#mrst{update_seq = 2}})
end),
- State = #mrst{fd=self(), update_seq=0},
- ?assertEqual({ok, State#mrst{update_seq=1}}, recompact(State)),
- meck:unload(couch_index_updater)
+ try
+ State = #mrst{fd=self(), update_seq=0},
+ ?assertEqual({ok, State#mrst{update_seq = 2}}, recompact(State))
+ after
+ meck:unload(couch_index_updater)
+ end
end).
recompact_exceeded_retry_count() ->
@@ -322,11 +325,16 @@
fun(_, _, _) ->
exit(error)
end),
- State = #mrst{fd=self(), db_name=foo, idx_name=bar},
- ExpectedError = {exceeded_recompact_retry_count,
- [{db_name, foo}, {idx_name, bar}]},
- ?assertError(ExpectedError, recompact(State)),
- meck:unload(couch_index_updater)
+ ok = meck:expect(couch_log, warning, fun(_, _) -> ok end),
+ try
+ State = #mrst{fd=self(), db_name=foo, idx_name=bar},
+ ExpectedError = {exceeded_recompact_retry_count,
+ [{db_name, foo}, {idx_name, bar}]},
+ ?assertError(ExpectedError, recompact(State))
+ after
+ meck:unload(couch_log),
+ meck:unload(couch_index_updater)
+ end
end).
-endif.