Skip to content

Commit

Permalink
Update http_client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrzaszcz committed Aug 3, 2016
1 parent 8d409da commit 934ed82
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions test/ejabberd_tests/tests/http_client_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,29 @@
-include_lib("common_test/include/ct.hrl").

all() ->
[request_test,
[get_test,
post_test,
request_timeout_test,
pool_timeout_test
].

init_per_suite(Config) ->
ConfigWithModules = dynamic_modules:save_modules(domain(), Config),
dynamic_modules:ensure_modules(domain(), required_modules()),
http_helper:start(8080, '_', fun process_request/1),
ConfigWithModules.

process_request(Req) ->
{Sleep, Req1} = cowboy_req:qs_val(<<"sleep">>, Req),
case Sleep of
<<"true">> -> timer:sleep(100);
_ -> ok
end,
{ok, Req2} = cowboy_req:reply(200, [{<<"content-type">>, <<"text/plain">>}], <<"OK">>, Req1),
Req2.

end_per_suite(Config) ->
http_helper:stop(),
dynamic_modules:restore_modules(domain(), Config).

init_per_testcase(request_timeout_test, Config) ->
Expand All @@ -40,7 +52,8 @@ init_per_testcase(request_timeout_test, Config) ->
init_per_testcase(pool_timeout_test, Config) ->
call(start_pool, [domain(), tmp_pool, [{host, "http://localhost:8080"},
{pool_size, 1},
{max_overflow, 0}]]),
{max_overflow, 0},
{pool_timeout, 10}]]),
Config;
init_per_testcase(_TC, Config) ->
call(start_pool, [domain(), tmp_pool, [{host, "http://localhost:8080"}]]),
Expand All @@ -49,26 +62,26 @@ init_per_testcase(_TC, Config) ->
end_per_testcase(_TC, _Config) ->
call(stop_pool, [domain(), tmp_pool]).

request_test(_Config) ->
http_helper:listen_once(self(), 8080, <<"test request">>, <<"OK">>),
get_test(_Config) ->
Pool = call(get_pool, [domain(), tmp_pool]),
Result = call(get, [Pool, <<"/some/path">>, []]),
{ok, {<<"200">>, <<"OK">>}} = Result.

post_test(_Config) ->
Pool = call(get_pool, [domain(), tmp_pool]),
Result = call(make_request, [Pool, <<"">>, <<"GET">>, [], <<"test request">>]),
Result = call(post, [Pool, <<"/some/path">>, [], <<"test request">>]),
{ok, {<<"200">>, <<"OK">>}} = Result.

request_timeout_test(_Config) ->
http_helper:listen_once(self(), 8080, <<"test request">>, none),
Pool = call(get_pool, [domain(), tmp_pool]),
Result = call(make_request, [Pool, <<"">>, <<"GET">>, [], <<"test request">>]),
Result = call(get, [Pool, <<"/some/path?sleep=true">>, []]),
{error, request_timeout} = Result.

pool_timeout_test(_Config) ->
http_helper:listen_once(self(), 8080, <<"test request">>, none),
Pool = call(get_pool, [domain(), tmp_pool]),
spawn_link(fun() ->
call(make_request, [Pool, <<"">>, <<"GET">>, [], <<"test request">>])
end),
spawn_link(fun() -> call(get, [Pool, <<"/some/path?sleep=true">>, []]) end),
timer:sleep(10), % wait for the only pool worker to start handling the request
Result = call(make_request, [Pool, <<"">>, <<"GET">>, [], <<"test request">>]),
Result = call(get, [Pool, <<"/some/path">>, []]),
{error, pool_timeout} = Result.

required_modules() ->
Expand Down

0 comments on commit 934ed82

Please sign in to comment.