couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [09/48] couch commit: updated refs/heads/master to 7776921
Date Sat, 04 Apr 2015 23:29:04 GMT
Implement with_process_restart and wait_process

Implement additional helper functions for test suite to follow DRY.

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/a60b88ff
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/a60b88ff
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/a60b88ff

Branch: refs/heads/master
Commit: a60b88ff9d5b58597bf0a21382d51bda5d0ade5d
Parents: bc1963f
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Tue Jan 27 10:24:33 2015 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Tue Feb 10 10:40:15 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/a60b88ff/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index 1c3c93f..d4eb882 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -26,6 +26,9 @@
 
 -export([stop_sync_throw/2, stop_sync_throw/3, stop_sync_throw/4]).
 
+-export([with_process_restart/1, with_process_restart/2, with_process_restart/3]).
+-export([wait_process/1, wait_process/2]).
+
 srcdir() ->
     code:priv_dir(couch) ++ "/../../".
 
@@ -155,3 +158,40 @@ stop_sync_throw(Pid, Fun, Error, Timeout) ->
         Else ->
             Else
     end.
+
+with_process_restart(Name) ->
+    {Pid, true} = with_process_restart(
+        fun() -> exit(whereis(Name), shutdown) end, Name),
+    Pid.
+
+with_process_restart(Name, Fun) ->
+    with_process_restart(Name, Fun, 5000).
+
+with_process_restart(Name, Fun, Timeout) ->
+    ok = stop_sync(Name, Fun),
+    case wait_process(Name, Timeout) of
+    timeout ->
+        timeout;
+    Pid ->
+        Pid
+    end.
+
+wait_process(Name) ->
+    wait_process(Name, 5000).
+wait_process(Name, Timeout) ->
+    Now = now_us(),
+    wait_process(Name, Timeout * 1000, Now, Now).
+
+wait_process(_Name, Timeout, Started, Prev) when Prev - Started > Timeout ->
+    timeout;
+wait_process(Name, Timeout, Started, _Prev) ->
+    case whereis(Name) of
+    undefined ->
+        wait_process(Name, Timeout, Started, now_us());
+    Pid ->
+        Pid
+    end.
+
+now_us() ->
+    {MegaSecs, Secs, MicroSecs} = now(),
+    (MegaSecs * 1000000 + Secs) * 1000000 + MicroSecs.


Mime
View raw message