aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-05-13 13:18:01 +0200
committerLoïc Hoguin <[email protected]>2019-05-13 13:18:01 +0200
commit3aa7168404e62f9ea9e290380b93569eff4372a8 (patch)
treeab8cb6f89c2e5e3abb5cb27d34b9b902b427625f /test
parentcfd702a716f834c431abd46532e8cfa4debd1468 (diff)
downloadgun-3aa7168404e62f9ea9e290380b93569eff4372a8.tar.gz
gun-3aa7168404e62f9ea9e290380b93569eff4372a8.tar.bz2
gun-3aa7168404e62f9ea9e290380b93569eff4372a8.zip
Add the disconnect event callback
Diffstat (limited to 'test')
-rw-r--r--test/event_SUITE.erl20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/event_SUITE.erl b/test/event_SUITE.erl
index 383ac46..50a1ce2 100644
--- a/test/event_SUITE.erl
+++ b/test/event_SUITE.erl
@@ -20,6 +20,7 @@
-import(ct_helper, [config/2]).
-import(ct_helper, [doc/1]).
+-import(gun_test, [init_origin/1]).
all() ->
ct_helper:all(?MODULE).
@@ -99,6 +100,21 @@ connect_end_ok(Config) ->
} = do_receive_event(connect_end),
gun:close(Pid).
+disconnect(_) ->
+ doc("Confirm that the disconnect event callback is called on disconnect."),
+ Self = self(),
+ Opts = #{event_handler => {?MODULE, Self}},
+ {ok, OriginPid, OriginPort} = init_origin(tcp),
+ {ok, Pid} = gun:open("localhost", OriginPort, Opts),
+ {ok, http} = gun:await_up(Pid),
+ %% We make the origin exit to trigger a disconnect.
+ unlink(OriginPid),
+ exit(OriginPid, shutdown),
+ #{
+ reason := closed
+ } = do_receive_event(disconnect),
+ gun:close(Pid).
+
%% Internal.
do_receive_event(Event) ->
@@ -122,3 +138,7 @@ connect_start(EventData, Pid) ->
connect_end(EventData, Pid) ->
Pid ! {?FUNCTION_NAME, EventData},
Pid.
+
+disconnect(EventData, Pid) ->
+ Pid ! {?FUNCTION_NAME, EventData},
+ Pid.