From 734f57aa8a79a942767d0707a053dbee6caa1290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sun, 17 Apr 2011 13:36:51 +0200 Subject: ct: Throw garbage at the server then check if it's still up. Basically: cat /dev/urandom | nc host port Only run this test if cat and nc are available. --- test/http_SUITE.erl | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl index da43536..6807f78 100644 --- a/test/http_SUITE.erl +++ b/test/http_SUITE.erl @@ -18,7 +18,7 @@ -export([all/0, groups/0, init_per_suite/1, end_per_suite/1, init_per_group/2, end_per_group/2]). %% ct. --export([headers_dupe/1, pipeline/1, raw/1]). %% http. +-export([headers_dupe/1, nc_rand/1, pipeline/1, raw/1]). %% http. -export([http_200/1, http_404/1, websocket/1]). %% http and https. %% ct. @@ -28,7 +28,7 @@ all() -> groups() -> BaseTests = [http_200, http_404], - [{http, [], [headers_dupe, pipeline, raw, websocket] ++ BaseTests}, + [{http, [], [headers_dupe, nc_rand, pipeline, raw, websocket] ++ BaseTests}, {https, [], BaseTests}]. init_per_suite(Config) -> @@ -100,6 +100,25 @@ headers_dupe(Config) -> nomatch = binary:match(Data, <<"Connection: keep-alive">>), ok = gen_tcp:close(Socket). +nc_rand(Config) -> + Cat = os:find_executable("cat"), + Nc = os:find_executable("nc"), + case {Cat, Nc} of + {false, _} -> + {skip, {notfound, cat}}; + {_, false} -> + {skip, {notfound, nc}}; + _Good -> + %% Throw garbage at the server then check if it's still up. + {port, Port} = lists:keyfind(port, 1, Config), + [nc_rand_run(Port) || _N <- lists:seq(1, 100)], + Packet = "GET / HTTP/1.0\r\nHost: localhost\r\n\r\n", + {Packet, 200} = raw_req(Packet, Config) + end. + +nc_rand_run(Port) -> + os:cmd("cat /dev/urandom | nc localhost " ++ integer_to_list(Port)). + pipeline(Config) -> {port, Port} = lists:keyfind(port, 1, Config), {ok, Socket} = gen_tcp:connect("localhost", Port, -- cgit v1.2.3