From 2dd60838510f834b005c266cab7c657a68239ecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 14 Dec 2017 11:20:39 +0100 Subject: Change the {gone, Reason} to {shutdown, Reason} plus small fixes The reason for this change is to avoid annoying supervisor logs when SASL logging is enabled. --- src/gun.erl | 3 ++- test/fake_transport.erl | 2 +- test/gun_SUITE.erl | 24 ++++++++++++------------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/gun.erl b/src/gun.erl index e6ed183..be9e15d 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -601,7 +601,7 @@ down(State=#state{owner=Owner, opts=Opts, protocol=Protocol, protocol_state=Prot last_error=Reason}, maps:get(retry, Opts, 5)). retry(#state{last_error=Reason}, 0) -> - error({gone, Reason}); + exit({shutdown, Reason}); retry(State=#state{keepalive_ref=KeepaliveRef}, Retries) when is_reference(KeepaliveRef) -> _ = erlang:cancel_timer(KeepaliveRef), %% Flush if we have a keepalive message @@ -784,6 +784,7 @@ ws_loop(State=#state{parent=Parent, owner=Owner, owner_ref=OwnerRef, socket=Sock error_logger:error_msg("Unexpected message: ~w~n", [Any]) end. +-spec owner_gone(_) -> no_return(). owner_gone(normal) -> exit(normal); owner_gone(shutdown) -> exit(shutdown); owner_gone(Shutdown = {shutdown, _}) -> exit(Shutdown); diff --git a/test/fake_transport.erl b/test/fake_transport.erl index 80e9afd..0baa9fa 100644 --- a/test/fake_transport.erl +++ b/test/fake_transport.erl @@ -1,4 +1,4 @@ -module(fake_transport). -compile(export_all). -send(Socket, Message) -> ok. +send(_, _) -> ok. diff --git a/test/gun_SUITE.erl b/test/gun_SUITE.erl index 9f003e8..ead4a81 100644 --- a/test/gun_SUITE.erl +++ b/test/gun_SUITE.erl @@ -25,7 +25,7 @@ connect_timeout(_) -> {ok, Pid} = gun:open("localhost", 12345, #{connect_timeout => 1000, retry => 0}), Ref = monitor(process, Pid), receive - {'DOWN', Ref, process, Pid, {{gone, _}, _}} -> + {'DOWN', Ref, process, Pid, {shutdown, _}} -> ok after 5000 -> error(timeout) @@ -36,7 +36,7 @@ connect_timeout_infinity(_) -> {ok, Pid} = gun:open("localhost", 12345, #{connect_timeout => infinity, retry => 0}), Ref = monitor(process, Pid), receive - {'DOWN', Ref, process, Pid, {{gone, _}, _}} -> + {'DOWN', Ref, process, Pid, {shutdown, _}} -> ok after 5000 -> error(timeout) @@ -72,7 +72,7 @@ detect_owner_gone_ws(_) -> gun:await_up(ConnPid), gun:ws_upgrade(ConnPid, "/", []), receive - {gun_ws_upgrade, Pid, ok, _} -> + {gun_ws_upgrade, ConnPid, ok, _} -> ok after 1000 -> error(timeout) @@ -93,12 +93,12 @@ detect_owner_gone_ws(_) -> error(timeout) end. -gone_reason(_) -> +shutdown_reason(_) -> doc("The last connection failure must be propagated."), {ok, Pid} = gun:open("localhost", 12345, #{retry => 0}), Ref = monitor(process, Pid), receive - {'DOWN', Ref, process, Pid, {{gone, econnrefused}, _}} -> + {'DOWN', Ref, process, Pid, {shutdown, econnrefused}} -> ok after 200 -> error(timeout) @@ -118,7 +118,7 @@ keepalive_infinity(_) -> retry => 0}), Ref = monitor(process, Pid), receive - {'DOWN', Ref, process, Pid, {{gone, _}, _}} -> + {'DOWN', Ref, process, Pid, {shutdown, _}} -> ok after 5000 -> error(timeout) @@ -155,7 +155,7 @@ retry_0(_) -> {ok, Pid} = gun:open("localhost", 12345, #{retry => 0, retry_timeout => 500}), Ref = monitor(process, Pid), receive - {'DOWN', Ref, process, Pid, {{gone, _}, _}} -> + {'DOWN', Ref, process, Pid, {shutdown, _}} -> ok after 200 -> error(timeout) @@ -166,7 +166,7 @@ retry_1(_) -> {ok, Pid} = gun:open("localhost", 12345, #{retry => 1, retry_timeout => 500}), Ref = monitor(process, Pid), receive - {'DOWN', Ref, process, Pid, {{gone, _}, _}} -> + {'DOWN', Ref, process, Pid, {shutdown, _}} -> ok after 700 -> error(timeout) @@ -177,16 +177,16 @@ retry_timeout(_) -> {ok, Pid} = gun:open("localhost", 12345, #{retry => 1, retry_timeout => 1000}), Ref = monitor(process, Pid), receive - {'DOWN', Ref, process, Pid, {{gone, _}, _}} -> - error(gone_too_early) + {'DOWN', Ref, process, Pid, {shutdown, _}} -> + error(shutdown_too_early) after 800 -> ok end, receive - {'DOWN', Ref, process, Pid, {{gone, _}, _}} -> + {'DOWN', Ref, process, Pid, {shutdown, _}} -> ok after 400 -> - error(gone_too_late) + error(shutdown_too_late) end. transform_header_name(_) -> -- cgit v1.2.3