couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [26/48] couch commit: updated refs/heads/master to 7776921
Date Sat, 04 Apr 2015 23:29:21 GMT
Add test_util:wait function

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

Branch: refs/heads/master
Commit: 0d5acb1354c717a3b1350ca511d03e7817f48586
Parents: 5e95b1a
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Tue Feb 3 12:22:25 2015 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Tue Feb 10 11:04:52 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/0d5acb13/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index ec2029d..48b57f0 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -28,6 +28,7 @@
 
 -export([with_process_restart/1, with_process_restart/2, with_process_restart/3]).
 -export([wait_process/1, wait_process/2]).
+-export([wait/1, wait/2, wait/3]).
 
 -export([start/1, start/2, start/3, stop/1]).
 
@@ -183,20 +184,38 @@ with_process_restart(Name, Fun, Timeout) ->
         Pid
     end.
 
+
 wait_process(Name) ->
     wait_process(Name, 5000).
 wait_process(Name, Timeout) ->
+    wait(fun() ->
+       case whereis(Name) of
+       undefined ->
+          wait;
+       Pid ->
+          Pid
+       end
+    end, Timeout).
+
+wait(Fun) ->
+    wait(Fun, 5000, 50).
+
+wait(Fun, Timeout) ->
+    wait(Fun, Timeout, 50).
+
+wait(Fun, Timeout, Delay) ->
     Now = now_us(),
-    wait_process(Name, Timeout * 1000, Now, Now).
+    wait(Fun, Timeout * 1000, Delay, Now, Now).
 
-wait_process(_Name, Timeout, Started, Prev) when Prev - Started > Timeout ->
+wait(_Fun, Timeout, _Delay, 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
+wait(Fun, Timeout, Delay, Started, _Prev) ->
+    case Fun() of
+    wait ->
+        ok = timer:sleep(Delay),
+        wait(Fun, Timeout, Delay, Started, now_us());
+    Else ->
+        Else
     end.
 
 start(Module) ->


Mime
View raw message