aboutsummaryrefslogtreecommitdiffstats
path: root/test/gun_test_event_h.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2020-03-27 13:37:18 +0100
committerLoïc Hoguin <[email protected]>2020-03-27 13:38:38 +0100
commit5a33fda25f34c0d7446ea14e561643ddd0ebe351 (patch)
treec11555d750af7725b7e5e5756f17ee5fc4e36c9d /test/gun_test_event_h.erl
parent6a73d965b92370a4134a17bc3f1da75d66ca06b8 (diff)
downloadgun-5a33fda25f34c0d7446ea14e561643ddd0ebe351.tar.gz
gun-5a33fda25f34c0d7446ea14e561643ddd0ebe351.tar.bz2
gun-5a33fda25f34c0d7446ea14e561643ddd0ebe351.zip
Improve test timeout handling in gun_SUITE
Instead of timeouts, favor receiving events from the event handler gun_test_event_h. Remove most other timeouts in particular receive timeouts in favor of a Common Test timetrap timeout global to this test suite of 30 seconds.
Diffstat (limited to 'test/gun_test_event_h.erl')
-rw-r--r--test/gun_test_event_h.erl65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/gun_test_event_h.erl b/test/gun_test_event_h.erl
new file mode 100644
index 0000000..98b2669
--- /dev/null
+++ b/test/gun_test_event_h.erl
@@ -0,0 +1,65 @@
+%% Copyright (c) 2020, Loïc Hoguin <[email protected]>
+%%
+%% Permission to use, copy, modify, and/or distribute this software for any
+%% purpose with or without fee is hereby granted, provided that the above
+%% copyright notice and this permission notice appear in all copies.
+%%
+%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+-module(gun_test_event_h).
+-compile(export_all).
+-compile(nowarn_export_all).
+
+init(Event, State) -> common(?FUNCTION_NAME, Event, State).
+domain_lookup_start(Event, State) -> common(?FUNCTION_NAME, Event, State).
+domain_lookup_end(Event, State) -> common(?FUNCTION_NAME, Event, State).
+connect_start(Event, State) -> common(?FUNCTION_NAME, Event, State).
+connect_end(Event, State) -> common(?FUNCTION_NAME, Event, State).
+tls_handshake_start(Event, State) -> common(?FUNCTION_NAME, Event, State).
+tls_handshake_end(Event, State) -> common(?FUNCTION_NAME, Event, State).
+request_start(Event, State) -> common(?FUNCTION_NAME, Event, State).
+request_headers(Event, State) -> common(?FUNCTION_NAME, Event, State).
+request_end(Event, State) -> common(?FUNCTION_NAME, Event, State).
+push_promise_start(Event, State) -> common(?FUNCTION_NAME, Event, State).
+push_promise_end(Event, State) -> common(?FUNCTION_NAME, Event, State).
+response_start(Event, State) -> common(?FUNCTION_NAME, Event, State).
+response_inform(Event, State) -> common(?FUNCTION_NAME, Event, State).
+response_headers(Event, State) -> common(?FUNCTION_NAME, Event, State).
+response_trailers(Event, State) -> common(?FUNCTION_NAME, Event, State).
+response_end(Event, State) -> common(?FUNCTION_NAME, Event, State).
+ws_upgrade(Event, State) -> common(?FUNCTION_NAME, Event, State).
+ws_recv_frame_start(Event, State) -> common(?FUNCTION_NAME, Event, State).
+ws_recv_frame_header(Event, State) -> common(?FUNCTION_NAME, Event, State).
+ws_recv_frame_end(Event, State) -> common(?FUNCTION_NAME, Event, State).
+ws_send_frame_start(Event, State) -> common(?FUNCTION_NAME, Event, State).
+ws_send_frame_end(Event, State) -> common(?FUNCTION_NAME, Event, State).
+protocol_changed(Event, State) -> common(?FUNCTION_NAME, Event, State).
+transport_changed(Event, State) -> common(?FUNCTION_NAME, Event, State).
+origin_changed(Event, State) -> common(?FUNCTION_NAME, Event, State).
+cancel(Event, State) -> common(?FUNCTION_NAME, Event, State).
+disconnect(Event, State) -> common(?FUNCTION_NAME, Event, State).
+terminate(Event, State) -> common(?FUNCTION_NAME, Event, State).
+
+common(EventType, Event, State=Pid) ->
+ Pid ! {self(), EventType, Event#{
+ ts => erlang:system_time(millisecond)
+ }},
+ State.
+
+receive_event(Pid) ->
+ receive
+ Msg = {Pid, EventType, Event} when is_atom(EventType), is_map(Event) ->
+ Msg
+ end.
+
+receive_event(Pid, EventType) ->
+ receive
+ Msg = {Pid, EventType, Event} when is_map(Event) ->
+ Msg
+ end.