aboutsummaryrefslogtreecommitdiffstats
path: root/lib/common_test/test
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common_test/test')
-rw-r--r--lib/common_test/test/ct_gen_conn_SUITE_data/conn_SUITE.erl68
1 files changed, 51 insertions, 17 deletions
diff --git a/lib/common_test/test/ct_gen_conn_SUITE_data/conn_SUITE.erl b/lib/common_test/test/ct_gen_conn_SUITE_data/conn_SUITE.erl
index 1404df6410..19eb1211fa 100644
--- a/lib/common_test/test/ct_gen_conn_SUITE_data/conn_SUITE.erl
+++ b/lib/common_test/test/ct_gen_conn_SUITE_data/conn_SUITE.erl
@@ -73,24 +73,28 @@ handles_to_multi_conn_pids(_Config) ->
ConnPid3 = ct_gen_conn:get_conn_pid(Handle3),
{true,true} = {is_process_alive(Handle3),is_process_alive(ConnPid3)},
+ monitor_procs([Handle1,ConnPid1,Handle2,ConnPid2,Handle3,ConnPid3]),
+
ok = proto:close(Handle1),
- ct:sleep(100),
+ ok = wait_procs_down([Handle1,ConnPid1]),
{false,false} = {is_process_alive(Handle1),is_process_alive(ConnPid1)},
{true,true} = {is_process_alive(Handle2),is_process_alive(ConnPid2)},
ok = proto:kill_conn_proc(Handle2),
- ct:sleep(100),
+ ok = wait_procs_down([ConnPid2]),
{true,false} = {is_process_alive(Handle2),is_process_alive(ConnPid2)},
ConnPid2x = ct_gen_conn:get_conn_pid(Handle2),
true = is_process_alive(ConnPid2x),
+ monitor_procs([ConnPid2x]),
+
ok = proto:close(Handle2),
- ct:sleep(100),
+ ok = wait_procs_down([Handle2,ConnPid2x]),
{false,false} = {is_process_alive(Handle2),is_process_alive(ConnPid2x)},
application:set_env(ct_test, reconnect, false),
ok = proto:kill_conn_proc(Handle3),
- ct:sleep(100),
+ ok = wait_procs_down([Handle3,ConnPid3]),
{false,false} = {is_process_alive(Handle3),is_process_alive(ConnPid3)},
ok.
@@ -116,24 +120,28 @@ handles_to_single_conn_pids(_Config) ->
{undefined,Handle3,_,_}] = lists:sort(ct_util:get_connections(ConnPid)),
ct:pal("CONNS = ~n~p", [Conns]),
+ monitor_procs([Handle1,Handle2,Handle3,ConnPid]),
ok = proto:close(Handle1),
- ct:sleep(100),
+ ok = wait_procs_down([Handle1]),
{false,true} = {is_process_alive(Handle1),is_process_alive(ConnPid)},
ok = proto:kill_conn_proc(Handle2),
- ct:sleep(100),
+ ok = wait_procs_down([ConnPid]),
NewConnPid = ct_gen_conn:get_conn_pid(Handle2),
NewConnPid = ct_gen_conn:get_conn_pid(Handle3),
true = is_process_alive(Handle2),
true = is_process_alive(Handle3),
+ false = is_process_alive(ConnPid),
+
+ monitor_procs([NewConnPid]),
ok = proto:close(Handle2),
- ct:sleep(100),
+ ok = wait_procs_down([Handle2]),
{false,true} = {is_process_alive(Handle2),is_process_alive(NewConnPid)},
application:set_env(ct_test, reconnect, false),
ok = proto:kill_conn_proc(Handle3),
- ct:sleep(100),
+ ok = wait_procs_down([Handle3,NewConnPid]),
{false,false} = {is_process_alive(Handle3),is_process_alive(NewConnPid)},
ok.
@@ -158,30 +166,37 @@ names_to_multi_conn_pids(_Config) ->
Handle1 = proto:open(mconn1),
+ monitor_procs([Handle1,ConnPid1,Handle2,ConnPid2,Handle3,ConnPid3]),
+
ok = proto:close(mconn1),
- ct:sleep(100),
+ ok = wait_procs_down([Handle1,ConnPid1]),
{false,false} = {is_process_alive(Handle1),is_process_alive(ConnPid1)},
ok = proto:kill_conn_proc(Handle2),
- ct:sleep(100),
+ ok = wait_procs_down([ConnPid2]),
Handle2 = proto:open(mconn2), % should've been reconnected already
{true,false} = {is_process_alive(Handle2),is_process_alive(ConnPid2)},
ConnPid2x = ct_gen_conn:get_conn_pid(Handle2),
true = is_process_alive(ConnPid2x),
+ monitor_procs([ConnPid2x]),
+
ok = proto:close(mconn2),
- ct:sleep(100),
+ ok = wait_procs_down([Handle2,ConnPid2x]),
{false,false} = {is_process_alive(Handle2),is_process_alive(ConnPid2x)},
Handle2y = proto:open(mconn2),
ConnPid2y = ct_gen_conn:get_conn_pid(Handle2y),
{true,true} = {is_process_alive(Handle2y),is_process_alive(ConnPid2y)},
+
+ monitor_procs([Handle2y,ConnPid2y]),
+
ok = proto:close(mconn2),
- ct:sleep(100),
+ ok = wait_procs_down([Handle2y,ConnPid2y]),
{false,false} = {is_process_alive(Handle2y),is_process_alive(ConnPid2y)},
application:set_env(ct_test, reconnect, false),
ok = proto:kill_conn_proc(Handle3),
- ct:sleep(100),
+ ok = wait_procs_down([Handle3,ConnPid3]),
{false,false} = {is_process_alive(Handle3),is_process_alive(ConnPid3)},
ok.
@@ -211,16 +226,20 @@ names_to_single_conn_pids(_Config) ->
{sconn3,Handle3,_,_}] = lists:sort(ct_util:get_connections(ConnPid)),
ct:pal("CONNS on ~p = ~n~p", [ConnPid,Conns]),
+ monitor_procs([Handle1,Handle2,Handle3,ConnPid]),
+
ok = proto:close(sconn1),
- ct:sleep(100),
+ ok = wait_procs_down([Handle1]),
{false,true} = {is_process_alive(Handle1),is_process_alive(ConnPid)},
ok = proto:kill_conn_proc(Handle2),
- ct:sleep(100),
+ ok = wait_procs_down([ConnPid]),
{true,false} = {is_process_alive(Handle2),is_process_alive(ConnPid)},
Handle2 = proto:open(sconn2), % should've been reconnected already
NewConnPid = ct_gen_conn:get_conn_pid(Handle2),
true = is_process_alive(NewConnPid),
+
+ monitor_procs([NewConnPid]),
Conns1 = [{sconn2,Handle2,_,_},
{sconn3,Handle3,_,_}] =
@@ -228,14 +247,29 @@ names_to_single_conn_pids(_Config) ->
ct:pal("CONNS on ~p = ~n~p", [NewConnPid,Conns1]),
ok = proto:close(sconn2),
- ct:sleep(100),
+ ok = wait_procs_down([Handle2]),
{false,true} = {is_process_alive(Handle2),is_process_alive(NewConnPid)},
application:set_env(ct_test, reconnect, false),
ok = proto:kill_conn_proc(Handle3),
- ct:sleep(100),
+ ok = wait_procs_down([Handle3,NewConnPid]),
{false,false} = {is_process_alive(Handle3),is_process_alive(NewConnPid)},
ok.
+%%%-----------------------------------------------------------------
+monitor_procs(Pids) ->
+ [erlang:monitor(process,Pid) || Pid <- Pids],
+ ok.
+
+wait_procs_down([]) ->
+ ok;
+wait_procs_down(Pids) ->
+ receive
+ {'DOWN',_,process,Pid,_} ->
+ wait_procs_down(lists:delete(Pid,Pids))
+ after 2000 ->
+ timeout
+ end.
+