|
20 | 20 | -export([names/1, diagnostics/1, make/1, parts/1, cookie_hash/0, |
21 | 21 | is_running/2, is_process_running/2, |
22 | 22 | cluster_name/0, set_cluster_name/2, ensure_epmd/0, |
23 | | - all_running/0, name_type/0]). |
| 23 | + all_running/0, name_type/0, running_count/0, |
| 24 | + await_running_count/2]). |
24 | 25 |
|
25 | 26 | -include_lib("kernel/include/inet.hrl"). |
26 | 27 |
|
| 28 | +-define(SAMPLING_INTERVAL, 1000). |
| 29 | + |
27 | 30 | %%---------------------------------------------------------------------------- |
28 | 31 | %% Specs |
29 | 32 | %%---------------------------------------------------------------------------- |
|
37 | 40 | -spec cluster_name() -> binary(). |
38 | 41 | -spec set_cluster_name(binary(), rabbit_types:username()) -> 'ok'. |
39 | 42 | -spec all_running() -> [node()]. |
| 43 | +-spec running_count() -> integer(). |
| 44 | + |
| 45 | +-spec await_running_count(integer(), integer()) -> 'ok,' | {'error', atom()}. |
40 | 46 |
|
41 | 47 | %%---------------------------------------------------------------------------- |
42 | 48 |
|
@@ -85,3 +91,20 @@ ensure_epmd() -> |
85 | 91 | rabbit_nodes_common:ensure_epmd(). |
86 | 92 |
|
87 | 93 | all_running() -> rabbit_mnesia:cluster_nodes(running). |
| 94 | + |
| 95 | +running_count() -> length(all_running()). |
| 96 | + |
| 97 | +await_running_count(TargetCount, Timeout) -> |
| 98 | + Retries = floor(Timeout/?SAMPLING_INTERVAL), |
| 99 | + await_running_count_with_retries(TargetCount, Retries). |
| 100 | + |
| 101 | +await_running_count_with_retries(1, _Retries) -> true; |
| 102 | +await_running_count_with_retries(_TargetCount, Retries) when Retries =:= 0 -> |
| 103 | + {error, timeout}; |
| 104 | +await_running_count_with_retries(TargetCount, Retries) -> |
| 105 | + case running_count() >= TargetCount of |
| 106 | + true -> ok; |
| 107 | + false -> |
| 108 | + timer:sleep(?SAMPLING_INTERVAL), |
| 109 | + await_running_count_with_retries(TargetCount, Retries - 1) |
| 110 | + end. |
0 commit comments