You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by kx...@apache.org on 2015/04/05 01:28:59 UTC
[04/48] couch commit: updated refs/heads/master to 7776921
Implement test_util:stop_sync
COUCHDB-2547
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/cacca040
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/cacca040
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/cacca040
Branch: refs/heads/master
Commit: cacca040a28668e69829c21f3e2279a2f00c1f04
Parents: 4529e12
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 08:32:39 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:36:16 2015 -0800
----------------------------------------------------------------------
src/test_util.erl | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/cacca040/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index acf8b3d..219cf6b 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -22,6 +22,8 @@
-export([start_config/1, stop_config/1]).
-export([start_applications/1]).
+-export([stop_sync/1, stop_sync/2, stop_sync/3]).
+
srcdir() ->
code:priv_dir(couch) ++ "/../../".
@@ -114,3 +116,30 @@ stop_config(Pid) ->
after Timeout ->
throw({timeout_error, config_stop})
end.
+
+stop_sync(Name) ->
+ stop_sync(Name, shutdown).
+stop_sync(Name, Reason) ->
+ stop_sync(Name, Reason, 5000).
+
+stop_sync(Name, Reason, Timeout) when is_atom(Name) ->
+ stop_sync(whereis(Name), Reason, Timeout);
+stop_sync(Pid, Reason, Timeout) when is_atom(Reason) and is_pid(Pid) ->
+ stop_sync(Pid, fun() -> exit(Pid, Reason) end, Timeout);
+stop_sync(Pid, Fun, Timeout) when is_function(Fun) and is_pid(Pid) ->
+ MRef = erlang:monitor(process, Pid),
+ try
+ begin
+ catch unlink(Pid),
+ Res = (catch Fun()),
+ receive
+ {'DOWN', MRef, _, _, _} ->
+ Res
+ after Timeout ->
+ timeout
+ end
+ end
+ after
+ erlang:demonitor(MRef, [flush])
+ end;
+stop_sync(_, _, _) -> error(badarg).