Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand Down
9 changes: 7 additions & 2 deletions src/ehttpc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion test/ehttpc_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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_() ->
Expand Down
Loading