From cc424b01f8b86de965bcc7e5b5e5560a6b7ea385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sun, 30 Apr 2017 15:44:25 +0200 Subject: Fix the retry=0 case, add general gun test suite --- Makefile | 2 +- src/gun.erl | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index b984a07..3ad27f8 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ PROJECT_VERSION = 1.0.0-pre.2 # Options. PLT_APPS = ssl -CT_OPTS += -pa test -ct_hooks gun_ct_hook [] -boot start_sasl +CT_OPTS += -pa test -ct_hooks gun_ct_hook [] # -boot start_sasl CI_OTP ?= OTP-18.0.3 OTP-18.1.5 OTP-18.2.4.1 OTP-18.3.4.4 OTP-19.0.7 OTP-19.1.6 #CI_HIPE ?= $(lastword $(CI_OTP)) diff --git a/src/gun.erl b/src/gun.erl index 3edc698..44d818e 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -506,7 +506,7 @@ connect(State=#state{host=Host, port=Port, opts=Opts, transport=Transport=ranch_ end, up(State, Socket, Protocol, ProtoOptsKey); {error, _} -> - retry(State, Retries - 1) + retry(State, Retries) end; connect(State=#state{host=Host, port=Port, opts=Opts, transport=Transport}, Retries) -> TransportOpts = [binary, {active, false} @@ -520,7 +520,7 @@ connect(State=#state{host=Host, port=Port, opts=Opts, transport=Transport}, Retr end, up(State, Socket, Protocol, ProtoOptsKey); {error, _} -> - retry(State, Retries - 1) + retry(State, Retries) end. up(State=#state{owner=Owner, opts=Opts, transport=Transport}, Socket, Protocol, ProtoOptsKey) -> @@ -535,9 +535,8 @@ down(State=#state{owner=Owner, opts=Opts, protocol=Protocol, protocol_state=Prot retry(State#state{socket=undefined, protocol=undefined, protocol_state=undefined}, maps:get(retry, Opts, 5)). -%% Exit normally if the retry functionality has been disabled. retry(_, 0) -> - ok; + error(gone); retry(State=#state{keepalive_ref=KeepaliveRef}, Retries) when is_reference(KeepaliveRef) -> _ = erlang:cancel_timer(KeepaliveRef), %% Flush if we have a keepalive message @@ -546,13 +545,10 @@ retry(State=#state{keepalive_ref=KeepaliveRef}, Retries) when is_reference(Keepa after 0 -> ok end, - retry_loop(State#state{keepalive_ref=undefined}, Retries); + retry_loop(State#state{keepalive_ref=undefined}, Retries - 1); retry(State, Retries) -> - retry_loop(State, Retries). + retry_loop(State, Retries - 1). -%% Too many retries, give up. -retry_loop(_, 0) -> - error(gone); retry_loop(State=#state{parent=Parent, opts=Opts}, Retries) -> _ = erlang:send_after(maps:get(retry_timeout, Opts, 5000), self(), retry), receive -- cgit v1.2.3