aboutsummaryrefslogtreecommitdiffstats
path: root/test/gun_test_event_h.erl
blob: 98b2669254cd9e02d6296d7ce9ccf7ab051ea1f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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.