iilyak commented on a change in pull request #492: Test changes_listener dies 
on mem3_shards shutdown
URL: https://github.com/apache/couchdb/pull/492#discussion_r113716649
 
 

 ##########
 File path: src/mem3/src/mem3_shards.erl
 ##########
 @@ -726,4 +726,50 @@ 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)),
+        ChangesPid = (get_state(Pid))#st.changes_pid,
+        ?assert(is_process_alive(ChangesPid)),
+        true = test_util:stop_sync_throw(ChangesPid, shutdown, wait_timeout),
 
 Review comment:
   I don't think this is what you wanted to say here. I probably confused you 
with my suggestion, sorry about that. You would want to send a `shutdown` 
signal to `Pid` and check that `ChangesPid` terminates as well. 
   Here is how you can send a signal to one process but wait termination of 
another one.
   ```
   true = test_util:stop_sync_throw(ChangesPid, fun() -> exit(Pid, shutdown) 
end, wait_timeout),
   ```
   This unwinds as follows:
   - stop_sync_throw(NameOrPid, TerminationFun, Error)
   - stop_sync_throw(NameOrPid, TerminationFun, Error, 5000)
   - stop_sync(Pid, TerminationFun, Timeout) when is_function(TerminationFun) 
and is_pid(Pid)  
   - 
[monitor/TerminationFun()/receive/demonitor](https://github.com/apache/couchdb/blob/master/src/couch/src/test_util.erl#L135:L149)
   ```
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to