aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-05-13 14:04:34 +0200
committerLoïc Hoguin <[email protected]>2019-05-13 14:04:34 +0200
commita309f196d15d3045d2e70b2d7e23858f47adb7df (patch)
tree6af8caa19dbccd790b4eefed298a924f682e4322 /test
parent3aa7168404e62f9ea9e290380b93569eff4372a8 (diff)
downloadgun-a309f196d15d3045d2e70b2d7e23858f47adb7df.tar.gz
gun-a309f196d15d3045d2e70b2d7e23858f47adb7df.tar.bz2
gun-a309f196d15d3045d2e70b2d7e23858f47adb7df.zip
Add the terminate event
Diffstat (limited to 'test')
-rw-r--r--test/event_SUITE.erl19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/event_SUITE.erl b/test/event_SUITE.erl
index 50a1ce2..05bff8c 100644
--- a/test/event_SUITE.erl
+++ b/test/event_SUITE.erl
@@ -115,6 +115,18 @@ disconnect(_) ->
} = do_receive_event(disconnect),
gun:close(Pid).
+terminate(_) ->
+ doc("Confirm that the terminate event callback is called on terminate."),
+ Self = self(),
+ Opts = #{event_handler => {?MODULE, Self}},
+ {ok, Pid} = gun:open("localhost", 12345, Opts),
+ gun:close(Pid),
+ #{
+ state := not_connected,
+ reason := shutdown
+ } = do_receive_event(terminate),
+ ok.
+
%% Internal.
do_receive_event(Event) ->
@@ -128,6 +140,9 @@ do_receive_event(Event) ->
%% gun_event callbacks.
init(EventData, Pid) ->
+ %% We enable trap_exit to ensure we get a terminate event
+ %% when we call gun:close/1.
+ process_flag(trap_exit, true),
Pid ! {?FUNCTION_NAME, EventData},
Pid.
@@ -142,3 +157,7 @@ connect_end(EventData, Pid) ->
disconnect(EventData, Pid) ->
Pid ! {?FUNCTION_NAME, EventData},
Pid.
+
+terminate(EventData, Pid) ->
+ Pid ! {?FUNCTION_NAME, EventData},
+ Pid.