From f1e45c48da52e2b30971b7e6a8891ae956dcd43f Mon Sep 17 00:00:00 2001 From: "Paul J. Davis" Date: Tue, 25 Jul 2017 16:41:59 -0500 Subject: Fix regression test for COUCHDB-1283 This makes sure that we correctly synchronize with the process running compaction before we perform our desired assertions. Fixes #701 --- src/couch/test/couchdb_views_tests.erl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/couch/test/couchdb_views_tests.erl b/src/couch/test/couchdb_views_tests.erl index 616a3c8a4..65fc2b385 100644 --- a/src/couch/test/couchdb_views_tests.erl +++ b/src/couch/test/couchdb_views_tests.erl @@ -354,19 +354,30 @@ couchdb_1283() -> couch_mrview_index, MDb1#db.name, <<"_design/foo">>), % Start and pause compacton + WaitRef = erlang:make_ref(), + meck:expect(couch_mrview_index, compact, fun(Db, State, Opts) -> + receive {WaitRef, From, init} -> ok end, + From ! {WaitRef, inited}, + receive {WaitRef, go} -> ok end, + meck:passthrough([Db, State, Opts]) + end), + {ok, CPid} = gen_server:call(Pid, compact), - meck:wait(couch_mrview_index, compact, ['_', '_', '_'], 1000), - erlang:suspend_process(CPid), CRef = erlang:monitor(process, CPid), ?assert(is_process_alive(CPid)), + % Make sure that our compactor is waiting for us + % before we continue our assertions + CPid ! {WaitRef, self(), init}, + receive {WaitRef, inited} -> ok end, + % Make sure that a compaction process takes a monitor % on the database's main_pid ?assertEqual(true, lists:member(CPid, couch_db:monitored_by(MDb1))), % Finish compaction to and make sure the monitor % disappears - erlang:resume_process(CPid), + CPid ! {WaitRef, go}, wait_for_process_shutdown(CRef, normal, {reason, "Failure compacting view group"}), -- cgit v1.2.1