Skip to content

Commit 3691c2e

Browse files
jaydoanenickva
authored andcommitted
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
1 parent 9d99d6e commit 3691c2e

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/mem3/src/mem3_shards.erl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,4 +732,45 @@ wait_writer_result(WRef) ->
732732
spawn_link_mock_writer(Db, Shards, Timeout) ->
733733
erlang:spawn_link(fun() -> shard_writer(Db, Shards, Timeout) end).
734734

735+
736+
737+
mem3_shards_changes_test_() -> {
738+
"Test mem3_shards changes listener", {
739+
foreach,
740+
fun setup_changes/0, fun teardown_changes/1,
741+
[
742+
fun should_kill_changes_listener_on_shutdown/1
743+
]
744+
}
745+
}.
746+
747+
748+
setup_changes() ->
749+
ok = meck:expect(mem3_util, ensure_exists, ['_'],
750+
{ok, #db{name = <<"dbs">>, update_seq = 0}}),
751+
ok = meck:expect(couch_db, close, ['_'], ok),
752+
ok = application:start(config),
753+
{ok, Pid} = ?MODULE:start_link(),
754+
true = erlang:unlink(Pid),
755+
Pid.
756+
757+
758+
teardown_changes(Pid) ->
759+
true = exit(Pid, shutdown),
760+
ok = application:stop(config),
761+
meck:unload().
762+
763+
764+
should_kill_changes_listener_on_shutdown(Pid) ->
765+
?_test(begin
766+
?assert(is_process_alive(Pid)),
767+
{ok, ChangesPid} = get_changes_pid(),
768+
?assert(is_process_alive(ChangesPid)),
769+
true = test_util:stop_sync_throw(
770+
ChangesPid, fun() -> exit(Pid, shutdown) end, wait_timeout),
771+
?assertNot(is_process_alive(ChangesPid)),
772+
ok
773+
end).
774+
775+
735776
-endif.

0 commit comments

Comments
 (0)