diff --git a/changelog.md b/changelog.md index 877d9fa..047f01c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # ehttpc changes +## 0.7.8 + +- Made it possible to call `ehttpc:health_check` with a timeout of `infinity`. + ## 0.7.7 - Added TCP keepalive for the `keepalive` pool option, which used to be ignored. On Linux diff --git a/rebar.config b/rebar.config index df329c6..aa24c28 100644 --- a/rebar.config +++ b/rebar.config @@ -5,7 +5,7 @@ {deps, [ {gun, "2.1.0"}, {gproc, {git, "https://github.com/emqx/gproc", {tag, "0.9.0.1"}}}, - {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "1.0.10"}}} + {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "1.0.11"}}} ]}. {erl_opts, [ diff --git a/src/ehttpc.erl b/src/ehttpc.erl index fa58e43..948ac6d 100644 --- a/src/ehttpc.erl +++ b/src/ehttpc.erl @@ -146,9 +146,9 @@ get_state(Worker, Style) when is_pid(Worker) -> start_link(Pool, Id, Opts) -> gen_server:start_link(?MODULE, [Pool, Id, Opts], []). --spec health_check(pid(), integer()) -> ok | {error, term()}. +-spec health_check(pid(), timeout()) -> ok | {error, term()}. health_check(Worker, Timeout) -> - CallTimeout = Timeout + timer:seconds(2), + CallTimeout = health_check_call_timeout(Timeout), try gen_server:call(Worker, {health_check, Timeout}, CallTimeout) catch @@ -1246,6 +1246,11 @@ enqueue_latest_fn(_) -> fresh_expire_at(Timeout) when Timeout =:= infinity; is_integer(Timeout) -> {now_(), Timeout}. +health_check_call_timeout(infinity) -> + infinity; +health_check_call_timeout(Timeout) when is_integer(Timeout) -> + Timeout + timer:seconds(2). + parse_proxy_opts(Opts) -> %% Target host and port case proplists:get_value(proxy, Opts, undefined) of diff --git a/test/ehttpc_tests.erl b/test/ehttpc_tests.erl index 85901f1..141594e 100644 --- a/test/ehttpc_tests.erl +++ b/test/ehttpc_tests.erl @@ -448,7 +448,26 @@ health_check_test_() -> ) end ) - end} + end}, + %% infinity timeout + {timeout, 20, + ?_test( + ?WITH( + #{ + port => Port, + name => ?FUNCTION_NAME, + delay => 0 + }, + pool_opts(Port, true), + begin + Worker = ehttpc_pool:pick_worker(?POOL), + ?assertEqual( + ok, + ehttpc:health_check(Worker, infinity) + ) + end + ) + )} ]. health_check_abnormal_test_() ->