couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [04/48] couch commit: updated refs/heads/master to 7776921
Date Sat, 04 Apr 2015 23:28:59 GMT
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 <iilyak@ca.ibm.com>
Authored: Tue Jan 27 08:32:39 2015 -0800
Committer: ILYA Khlopotov <iilyak@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).


Mime
View raw message