summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-10-28 17:10:58 +0100
committerLoïc Hoguin <[email protected]>2018-10-28 17:10:58 +0100
commit8c69a0ddd9a11c634c86bf3ce59459c93ff211fc (patch)
treee392a2266a2ce116f4f72b28756955eb9a9e777d
parent39ade78b8706b43651429901ca9e078080680544 (diff)
downloadct_helper-8c69a0ddd9a11c634c86bf3ce59459c93ff211fc.tar.gz
ct_helper-8c69a0ddd9a11c634c86bf3ce59459c93ff211fc.tar.bz2
ct_helper-8c69a0ddd9a11c634c86bf3ce59459c93ff211fc.zip
Add ct_helper:is_process_down/1,2
Because is_process_alive might occur too fast.
-rw-r--r--src/ct_helper.erl19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ct_helper.erl b/src/ct_helper.erl
index 29d419f..73dd96a 100644
--- a/src/ct_helper.erl
+++ b/src/ct_helper.erl
@@ -25,6 +25,8 @@
-export([get_remote_pid_tcp/1]).
-export([get_remote_pid_tls/1]).
-export([ignore/3]).
+-export([is_process_down/1]).
+-export([is_process_down/2]).
-export([make_certs/0]).
-export([make_certs_in_ets/0]).
-export([name/0]).
@@ -148,6 +150,23 @@ get_remote_pid_tls(Socket) ->
ignore(M, F, A) ->
ct_helper_error_h:ignore(M, F, A).
+%% @doco Similar to erlang:is_process_alive/1 except
+%% it uses monitors and waits up to a timeout.
+%%
+%% The return value is also the opposite of alive (down).
+
+is_process_down(Pid) ->
+ is_process_down(Pid, 1000).
+
+is_process_down(Pid, Timeout) ->
+ MRef = monitor(process, Pid),
+ receive
+ {'DOWN', MRef, process, Pid, _} ->
+ true
+ after Timeout ->
+ false
+ end.
+
%% @doc Create a set of certificates.
-spec make_certs()