diff options
author | Siri Hansen <[email protected]> | 2016-06-09 14:52:35 +0200 |
---|---|---|
committer | Siri Hansen <[email protected]> | 2016-06-09 14:52:35 +0200 |
commit | 68ff9f3e4b5387cf38af7aeb1a8b7abbdaa867d8 (patch) | |
tree | b34c9396a56b03968beaf3cdbab56e4a8a4847d2 /lib | |
parent | 75e5cdabbcaaa12f043225ca8d361055a9d47b24 (diff) | |
parent | baf5751951f3463d599ccb958272ab6a6fec39b4 (diff) | |
download | otp-68ff9f3e4b5387cf38af7aeb1a8b7abbdaa867d8.tar.gz otp-68ff9f3e4b5387cf38af7aeb1a8b7abbdaa867d8.tar.bz2 otp-68ff9f3e4b5387cf38af7aeb1a8b7abbdaa867d8.zip |
Merge branch 'siri/cuddle-master'
* siri/cuddle-master:
[ct test] Wait for event receiver to be unregistered
[ct test] Flush messages from old client after close in telnet server
[ct test] Use monitor instead of ct:sleep
[ct test] Check that crypto is loaded, or skip netconf tests
[ct test] Reduce amount of data in netconfc1_SUITE:get_a_lot
Diffstat (limited to 'lib')
7 files changed, 125 insertions, 49 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. + diff --git a/lib/common_test/test/ct_netconfc_SUITE.erl b/lib/common_test/test/ct_netconfc_SUITE.erl index 03fbc17bd2..2919f01605 100644 --- a/lib/common_test/test/ct_netconfc_SUITE.erl +++ b/lib/common_test/test/ct_netconfc_SUITE.erl @@ -44,16 +44,28 @@ %% there will be clashes with logging processes etc). %%-------------------------------------------------------------------- init_per_suite(Config) -> - case application:load(crypto) of - {error,Reason} when Reason=/={already_loaded,crypto} -> - {skip, Reason}; - _ -> - case application:load(ssh) of - {error,Reason} when Reason=/={already_loaded,ssh} -> - {skip, Reason}; - _ -> - ct_test_support:init_per_suite(Config) - end + case check_crypto_and_ssh() of + ok -> + ct_test_support:init_per_suite(Config); + Skip -> + Skip + end. + +check_crypto_and_ssh() -> + (catch code:load_file(crypto)), + case code:is_loaded(crypto) of + {file,_} -> + case ssh:start() of + Ok when Ok==ok; Ok=={error,{already_started,ssh}} -> + ct:log("ssh started",[]), + ok; + Other -> + ct:log("could not start ssh: ~p",[Other]), + {skip, "SSH could not be started!"} + end; + Other -> + ct:log("could not load crypto: ~p",[Other]), + {skip, "crypto could not be loaded!"} end. end_per_suite(Config) -> diff --git a/lib/common_test/test/ct_netconfc_SUITE_data/netconfc1_SUITE.erl b/lib/common_test/test/ct_netconfc_SUITE_data/netconfc1_SUITE.erl index f34969683c..2aa6c4d354 100644 --- a/lib/common_test/test/ct_netconfc_SUITE_data/netconfc1_SUITE.erl +++ b/lib/common_test/test/ct_netconfc_SUITE_data/netconfc1_SUITE.erl @@ -124,8 +124,9 @@ end_per_testcase(_Case, _Config) -> ok. init_per_suite(Config) -> - case catch ssh:start() of - Ok when Ok==ok; Ok=={error,{already_started,ssh}} -> + (catch code:load_file(crypto)), + case {ssh:start(),code:is_loaded(crypto)} of + {Ok,{file,_}} when Ok==ok; Ok=={error,{already_started,ssh}} -> ct:log("ssh started",[]), SshDir = filename:join(filename:dirname(code:which(?MODULE)), "ssh_dir"), @@ -133,7 +134,7 @@ init_per_suite(Config) -> ct:log("netconf server started",[]), [{netconf_server,Server},{ssh_dir,SshDir}|Config]; Other -> - ct:log("could not start ssh: ~p",[Other]), + ct:log("could not start ssh or load crypto: ~p",[Other]), {skip, "SSH could not be started!"} end. @@ -360,7 +361,7 @@ get(Config) -> get_a_lot(Config) -> SshDir = ?config(ssh_dir,Config), {ok,Client} = open_success(SshDir), - Descr = lists:append(lists:duplicate(1000,"Description of myserver! ")), + Descr = lists:append(lists:duplicate(100,"Description of myserver! ")), Server = {server,[{xmlns,"myns"}],[{name,[],["myserver"]}, {description,[],[Descr]}]}, Data = lists:duplicate(100,Server), diff --git a/lib/common_test/test/ct_netconfc_SUITE_data/netconfc_remote_SUITE.erl b/lib/common_test/test/ct_netconfc_SUITE_data/netconfc_remote_SUITE.erl index 0a49cdabbb..a65275da43 100644 --- a/lib/common_test/test/ct_netconfc_SUITE_data/netconfc_remote_SUITE.erl +++ b/lib/common_test/test/ct_netconfc_SUITE_data/netconfc_remote_SUITE.erl @@ -62,14 +62,15 @@ stop_node(Case) -> init_per_suite(Config) -> - case ssh:start() of - Ok when Ok==ok; Ok=={error,{already_started,ssh}} -> + (catch code:load_file(crypto)), + case {ssh:start(),code:is_loaded(crypto)} of + {Ok,{file,_}} when Ok==ok; Ok=={error,{already_started,ssh}} -> ct:log("SSH started locally",[]), SshDir = filename:join(filename:dirname(code:which(?MODULE)), "ssh_dir"), [{ssh_dir,SshDir}|Config]; Other -> - ct:log("could not start ssh locally: ~p",[Other]), + ct:log("could not start ssh or load crypto locally: ~p",[Other]), {skip, "SSH could not be started locally!"} end. @@ -85,15 +86,15 @@ remote_crash(Config) -> {ok,Node} = ct_slave:start(nc_remote_crash), Pa = filename:dirname(code:which(?NS)), true = rpc:call(Node,code,add_patha,[Pa]), - - case rpc:call(Node,ssh,start,[]) of - Ok when Ok==ok; Ok=={error,{already_started,ssh}} -> + rpc:call(Node,code,load_file,[crypto]), + case {rpc:call(Node,ssh,start,[]),rpc:call(Node,code,is_loaded,[crypto])} of + {Ok,{file,_}} when Ok==ok; Ok=={error,{already_started,ssh}} -> ct:log("SSH started remote",[]), ns(Node,start,[?config(ssh_dir,Config)]), ct:log("netconf server started remote",[]), remote_crash(Node,Config); Other -> - ct:log("could not start ssh remote: ~p",[Other]), + ct:log("could not start ssh or load crypto remote: ~p",[Other]), {skip, "SSH could not be started remote!"} end. diff --git a/lib/common_test/test/ct_netconfc_SUITE_data/ns.erl b/lib/common_test/test/ct_netconfc_SUITE_data/ns.erl index 9fb1fb6547..e62bc617fa 100644 --- a/lib/common_test/test/ct_netconfc_SUITE_data/ns.erl +++ b/lib/common_test/test/ct_netconfc_SUITE_data/ns.erl @@ -279,7 +279,7 @@ send({CM,Ch},Data) -> %%% Split into many small parts and send to client send_frag({CM,Ch},Data) -> - Sz = rand:uniform(2000), + Sz = rand:uniform(1000), case Data of <<Chunk:Sz/binary,Rest/binary>> -> ssh_connection:send(CM, Ch, Chunk), diff --git a/lib/common_test/test/ct_test_support.erl b/lib/common_test/test/ct_test_support.erl index 477fcb8a26..e926abd885 100644 --- a/lib/common_test/test/ct_test_support.erl +++ b/lib/common_test/test/ct_test_support.erl @@ -484,7 +484,8 @@ get_events(_, Config) -> {event_receiver,CTNode} ! {self(),get_events}, Events = receive {event_receiver,Evs} -> Evs end, test_server:format(Level, "Stopping event receiver!~n", []), - {event_receiver,CTNode} ! stop, + {event_receiver,CTNode} ! {self(),stop}, + receive {event_receiver,stopped} -> ok end, Events. er() -> @@ -499,8 +500,9 @@ er_loop(Evs) -> {From,get_events} -> From ! {event_receiver,lists:reverse(Evs)}, er_loop(Evs); - stop -> + {From,stop} -> unregister(event_receiver), + From ! {event_receiver,stopped}, ok end. diff --git a/lib/common_test/test/telnet_server.erl b/lib/common_test/test/telnet_server.erl index 2c33cb268a..65300b0bdf 100644 --- a/lib/common_test/test/telnet_server.erl +++ b/lib/common_test/test/telnet_server.erl @@ -117,38 +117,64 @@ init_client(#state{client=Sock}=State) -> dbg("Server sending: ~p~n",["login: "]), R = case gen_tcp:send(Sock,"login: ") of ok -> - loop(State, 1); + loop(State); Error -> Error end, _ = gen_tcp:close(Sock), R. -loop(State, N) -> +loop(State=#state{client=Sock}) -> receive - {tcp,_,Data} -> + {tcp,Sock,Data} -> try handle_data(Data,State) of {ok,State1} -> - loop(State1, N); + loop(State1); closed -> + _ = flush(State), closed catch throw:Error -> + _ = flush(State), Error end; - {tcp_closed, _} -> + {tcp_closed,Sock} -> closed; - {tcp_error,_,Error} -> + {tcp_error,Sock,Error} -> {error,tcp,Error}; disconnect -> - Sock = State#state.client, dbg("Server closing connection on socket ~p~n", [Sock]), + timer:sleep(1000), ok = gen_tcp:close(Sock), - closed; + _ = flush(State); stop -> + _ = flush(State), stopped end. +flush(State=#state{client=Sock}) -> + receive + {tcp,Sock,Data} = M-> + dbg("Message flushed after close or error: ~p~n", [M]), + try handle_data(Data,State) of + {ok,State1} -> + flush(State1); + closed -> + flush(State) + catch + throw:Error -> + Error + end; + {tcp_closed,Sock} = M -> + dbg("Message flushed after close or error: ~p~n", [M]), + ok; + {tcp_error,Sock,Error} = M -> + dbg("Message flushed after close or error: ~p~n", [M]), + {error,tcp,Error} + after 100 -> + ok + end. + handle_data(Cmd,#state{break=true}=State) -> dbg("Server got data when in break mode: ~p~n",[Cmd]), handle_break_cmd(Cmd,State); |