diff options
author | Micael Karlberg <[email protected]> | 2019-07-25 16:09:43 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2019-07-25 19:10:29 +0200 |
commit | d61dcd7708c7e33c6c650b1293119157b269a37a (patch) | |
tree | 2f3cc77f6c9848f6da2ea5257a60112b34d3c123 | |
parent | f51d3b9ff7c7d92557d17f8da86f413bf30a094d (diff) | |
download | otp-d61dcd7708c7e33c6c650b1293119157b269a37a.tar.gz otp-d61dcd7708c7e33c6c650b1293119157b269a37a.tar.bz2 otp-d61dcd7708c7e33c6c650b1293119157b269a37a.zip |
[megaco|test] Attempt to catch and handle skip'able TCP cases
When waiting for the server command handler to start
listening, wait only for so long (5 seconds) and if
it has not managed to start listening before then,
we *skip* (because something is wrong with the *system*).
-rw-r--r-- | lib/megaco/test/megaco_tcp_test.erl | 122 |
1 files changed, 73 insertions, 49 deletions
diff --git a/lib/megaco/test/megaco_tcp_test.erl b/lib/megaco/test/megaco_tcp_test.erl index 1f09db265d..cc66a40f43 100644 --- a/lib/megaco/test/megaco_tcp_test.erl +++ b/lib/megaco/test/megaco_tcp_test.erl @@ -117,15 +117,39 @@ end_per_testcase(Case, Config) -> %% Test case definitions %%====================================================================== all() -> - [{group, start}, {group, sending}, {group, errors}]. + [ + {group, start}, + {group, sending}, + {group, errors} + ]. groups() -> - [{start, [], - [start_normal, start_invalid_opt, start_and_stop]}, - {sending, [], [sendreceive, block_unblock]}, - {errors, [], - [socket_failure, accept_process, accept_supervisor, - connection_supervisor, tcp_server]}]. + [{start, [], start_cases()}, + {sending, [], sending_cases()}, + {errors, [], errors_cases()}]. + +start_cases() -> + [ + start_normal, + start_invalid_opt, + start_and_stop + ]. + +sending_cases() -> + [ + sendreceive, + block_unblock + ]. + +errors_cases() -> + [ + socket_failure, + accept_process, + accept_supervisor, + connection_supervisor, + tcp_server + ]. + init_per_group(_GroupName, Config) -> Config. @@ -196,17 +220,8 @@ start_and_stop(Config) when is_list(Config) -> Client = client_start_command_handler(ClientNode, ClientCmds), p("client command handler started: ~p", [Client]), - ok = - receive - {listening, Server} -> - p("received listening message from server [~p] => " - "send continue to client [~p]~n", [Server, Client]), - Client ! {continue, self()}, - ok - after 5000 -> - {error, server_timeout} - end, - + await_server_listening(Server, Client), + await_command_handler_completion([Server, Client], timer:seconds(20)), p("done"), ok. @@ -335,16 +350,7 @@ sendreceive(Config) when is_list(Config) -> Client = client_start_command_handler(ClientNode, ClientCmds), p("client command handler started: ~p", [Client]), - ok = - receive - {listening, Server} -> - p("received listening message from server [~p] => " - "send continue to client [~p]~n", [Server, Client]), - Client ! {continue, self()}, - ok - after 5000 -> - {error, server_timeout} - end, + await_server_listening(Server, Client), await_command_handler_completion([Server, Client], timer:seconds(20)), p("done"), @@ -544,27 +550,9 @@ block_unblock(Config) when is_list(Config) -> Client = client_start_command_handler(ClientNode, ClientCmds), p("client command handler started: ~p", [Client]), - ok = - receive - {listening, Server} -> - p("received listening message from server [~p] => " - "send continue to client [~p]~n", [Server, Client]), - Client ! {continue, self()}, - ok - after 5000 -> - {error, server_timeout} - end, - - ok = - receive - {blocked, Client} -> - p("received blocked message from client [~p] => " - "send continue to server [~p]~n", [Client, Server]), - Server ! {continue, self()}, - ok - after 5000 -> - {error, timeout} - end, + await_server_listening(Server, Client), + + await_client_blocked(Server, Client), await_command_handler_completion([Server, Client], timer:seconds(30)), p("done"), @@ -908,6 +896,42 @@ process_received_message(ReceiveHandle, ControlPid, SendHandle, BinMsg) %% Internal functions %%====================================================================== +await_server_listening(Server, Client) -> + receive + {listening, Server} -> + p("received listening message from server [~p] => " + "send continue to client [~p]" + "~n", [Server, Client]), + Client ! {continue, self()}, + ok + after 5000 -> + %% There is no normal reason why this should take any time. + %% Normally, this takes a few milli seconds. So, if we are not + %% up and running after 5 seconds, we give up and skip!! + exit(Server, kill), + exit(Client, kill), + ?SKIP("Server timeout (listen)") + end. + + +await_client_blocked(Server, Client) -> + receive + {blocked, Client} -> + p("received blocked message from client [~p] => " + "send continue to server [~p]~n", [Client, Server]), + Server ! {continue, self()}, + ok + after 5000 -> + %% There is no normal reason why this should take any time. + %% Normally, this takes a few milli seconds. So, if we are not + %% up and running after 5 seconds, we give up and skip!! + exit(Client, kill), + exit(Server, kill), + ?SKIP("Client timeout (blocked)") + end. + + + %% ------- Server command handler and utility functions ---------- server_start_command_handler(Node, Commands) -> |