diff --git a/test/ejabberd_tests/tests/http_client_SUITE.erl b/test/ejabberd_tests/tests/http_client_SUITE.erl index 6b243bb561d..11b18068634 100644 --- a/test/ejabberd_tests/tests/http_client_SUITE.erl +++ b/test/ejabberd_tests/tests/http_client_SUITE.erl @@ -20,7 +20,8 @@ -include_lib("common_test/include/ct.hrl"). all() -> - [request_test, + [get_test, + post_test, request_timeout_test, pool_timeout_test ]. @@ -28,9 +29,20 @@ all() -> 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) -> @@ -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"}]]), @@ -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() ->