summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Doane <jay.s.doane@gmail.com>2017-05-07 22:56:38 -0700
committerNick Vatamaniuc <nickva@users.noreply.github.com>2017-05-10 12:16:12 -0400
commit3691c2edbc6603963b1b5ad1bf97dfb69886c4a6 (patch)
tree39b125478550e2356494e939a32514ceb03997c2
parent9d99d6e8ef9b7076b9a25cffcb9ebd08655bbef6 (diff)
downloadcouchdb-3691c2edbc6603963b1b5ad1bf97dfb69886c4a6.tar.gz
Test changes_listener dies on mem3_shards shutdown
This adds a test to ensure that the changes_listener process exits when the mem3_shards process is shut down. COUCHDB-3398
-rw-r--r--src/mem3/src/mem3_shards.erl41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/mem3/src/mem3_shards.erl b/src/mem3/src/mem3_shards.erl
index a419e45a2..8d9cfb9c7 100644
--- a/src/mem3/src/mem3_shards.erl
+++ b/src/mem3/src/mem3_shards.erl
@@ -732,4 +732,45 @@ wait_writer_result(WRef) ->
spawn_link_mock_writer(Db, Shards, Timeout) ->
erlang:spawn_link(fun() -> shard_writer(Db, Shards, Timeout) end).
+
+
+mem3_shards_changes_test_() -> {
+ "Test mem3_shards changes listener", {
+ foreach,
+ fun setup_changes/0, fun teardown_changes/1,
+ [
+ fun should_kill_changes_listener_on_shutdown/1
+ ]
+ }
+}.
+
+
+setup_changes() ->
+ ok = meck:expect(mem3_util, ensure_exists, ['_'],
+ {ok, #db{name = <<"dbs">>, update_seq = 0}}),
+ ok = meck:expect(couch_db, close, ['_'], ok),
+ ok = application:start(config),
+ {ok, Pid} = ?MODULE:start_link(),
+ true = erlang:unlink(Pid),
+ Pid.
+
+
+teardown_changes(Pid) ->
+ true = exit(Pid, shutdown),
+ ok = application:stop(config),
+ meck:unload().
+
+
+should_kill_changes_listener_on_shutdown(Pid) ->
+ ?_test(begin
+ ?assert(is_process_alive(Pid)),
+ {ok, ChangesPid} = get_changes_pid(),
+ ?assert(is_process_alive(ChangesPid)),
+ true = test_util:stop_sync_throw(
+ ChangesPid, fun() -> exit(Pid, shutdown) end, wait_timeout),
+ ?assertNot(is_process_alive(ChangesPid)),
+ ok
+ end).
+
+
-endif.