@@ -732,4 +732,45 @@ wait_writer_result(WRef) ->
732732spawn_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