|
9 | 9 |
|
10 | 10 | -module(hackney_pool_tests). |
11 | 11 |
|
| 12 | +-export([connect/4]). |
| 13 | + |
12 | 14 | -include_lib("eunit/include/eunit.hrl"). |
13 | 15 | -include("hackney.hrl"). |
14 | 16 |
|
@@ -56,6 +58,10 @@ hackney_pool_integration_test_() -> |
56 | 58 | {"owner crash kills connection", fun test_owner_crash/0}, |
57 | 59 | {"checkin resets owner to pool", fun test_checkin_resets_owner/0}, |
58 | 60 | {"prewarm creates connections", fun test_prewarm/0}, |
| 61 | + {"connect timeout does not crash the pool", |
| 62 | + fun test_connect_timeout_does_not_crash_pool/0}, |
| 63 | + {"connect crash does not crash the pool", |
| 64 | + fun test_connect_crash_does_not_crash_pool/0}, |
59 | 65 | {"queue timeout", {timeout, 120, fun test_queue_timeout/0}}, |
60 | 66 | {"checkout timeout", {timeout, 120, fun test_checkout_timeout/0}}, |
61 | 67 | {"stop_pool releases in_use load_regulation slots", |
@@ -130,6 +136,14 @@ teardown_integration(_) -> |
130 | 136 | error_logger:tty(true), |
131 | 137 | ok. |
132 | 138 |
|
| 139 | +%% Stub transport: "slow.example" outlives the connect timeout, "crash.example" |
| 140 | +%% takes the connection process down while dialing. |
| 141 | +connect("slow.example", _Port, _Opts, _Timeout) -> |
| 142 | + timer:sleep(100), |
| 143 | + {error, simulated_timeout}; |
| 144 | +connect("crash.example", _Port, _Opts, _Timeout) -> |
| 145 | + erlang:error(simulated_crash). |
| 146 | + |
133 | 147 | setup_ssl() -> |
134 | 148 | error_logger:tty(false), |
135 | 149 | {ok, _} = application:ensure_all_started(cowboy), |
@@ -742,6 +756,24 @@ test_prewarm() -> |
742 | 756 |
|
743 | 757 | ok = hackney_pool:stop_pool(test_pool_prewarm). |
744 | 758 |
|
| 759 | +test_connect_timeout_does_not_crash_pool() -> |
| 760 | + PoolName = test_pool_connect_timeout, |
| 761 | + ok = hackney_pool:start_pool(PoolName, [{pool_size, 1}, {prewarm_count, 0}]), |
| 762 | + Opts = [{pool, PoolName}, {connect_timeout, 10}, {checkout_timeout, 1000}], |
| 763 | + ?assertEqual({error, connect_timeout}, |
| 764 | + hackney_pool:checkout("slow.example", 443, ?MODULE, Opts)), |
| 765 | + ?assert(is_process_alive(hackney_pool:find_pool(PoolName))), |
| 766 | + ok = hackney_pool:stop_pool(PoolName). |
| 767 | + |
| 768 | +test_connect_crash_does_not_crash_pool() -> |
| 769 | + PoolName = test_pool_connect_crash, |
| 770 | + ok = hackney_pool:start_pool(PoolName, [{pool_size, 1}, {prewarm_count, 0}]), |
| 771 | + Opts = [{pool, PoolName}, {connect_timeout, 1000}, {checkout_timeout, 2000}], |
| 772 | + ?assertMatch({error, {simulated_crash, _}}, |
| 773 | + hackney_pool:checkout("crash.example", 443, ?MODULE, Opts)), |
| 774 | + ?assert(is_process_alive(hackney_pool:find_pool(PoolName))), |
| 775 | + ok = hackney_pool:stop_pool(PoolName). |
| 776 | + |
745 | 777 | %%==================================================================== |
746 | 778 | %% Timeout Tests |
747 | 779 | %%==================================================================== |
|
0 commit comments