From 52b989079bacf423818a8e6d42c56095ad857635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 9 Feb 2021 14:36:39 +0100 Subject: Fix gun_pool:stop_pool/2,3 with default port --- src/gun_pool.erl | 13 ++++++++++--- test/pool_SUITE.erl | 7 +++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/gun_pool.erl b/src/gun_pool.erl index da31a42..8c40788 100644 --- a/src/gun_pool.erl +++ b/src/gun_pool.erl @@ -165,10 +165,17 @@ start_pool(Host, Port, Opts) -> stop_pool(Host, Port) -> stop_pool(Host, Port, #{}). --spec stop_pool(inet:hostname() | inet:ip_address(), inet:port_number(), req_opts()) +-type stop_opts() :: #{ + scope => any(), + transport => tcp | tls +}. + +-spec stop_pool(inet:hostname() | inet:ip_address(), inet:port_number(), stop_opts()) -> ok | {error, pool_not_found, atom()}. -stop_pool(Host, Port, ReqOpts) -> - case get_pool(iolist_to_binary([Host, $:, integer_to_binary(Port)]), ReqOpts) of +stop_pool(Host, Port, StopOpts) -> + Transport = maps:get(transport, StopOpts, gun:default_transport(Port)), + Authority = gun_http:host_header(Transport, Host, Port), + case get_pool(Authority, StopOpts) of undefined -> {error, pool_not_found, 'No pool was found for the given scope and authority.'}; diff --git a/test/pool_SUITE.erl b/test/pool_SUITE.erl index a48b75d..7643368 100644 --- a/test/pool_SUITE.erl +++ b/test/pool_SUITE.erl @@ -374,3 +374,10 @@ reconnect_h2(Config) -> end || {async, StreamRef} <- Streams2]. %% @todo reconnect_ws + +stop_pool(Config) -> + doc("Confirm the pool can be used for HTTP/1.1 connections."), + Port = config(port, Config), + {ok, ManagerPid} = gun_pool:start_pool("localhost", Port, #{scope => ?FUNCTION_NAME}), + gun_pool:await_up(ManagerPid), + gun_pool:stop_pool("localhost", Port, #{scope => ?FUNCTION_NAME}). -- cgit v1.2.3