aboutsummaryrefslogtreecommitdiffstats
path: root/test/handlers
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-03-26 18:49:09 +0200
committerLoïc Hoguin <[email protected]>2018-03-26 18:53:07 +0200
commit5964273cc4354b7378b8bdf49fe455d2b46d7c3b (patch)
tree38194d0ae9a16056fff8e1c062fe6c6267d2d24c /test/handlers
parent4d5174632cc1feac541697b18e6fbbdd0eed021b (diff)
downloadcowboy-5964273cc4354b7378b8bdf49fe455d2b46d7c3b.tar.gz
cowboy-5964273cc4354b7378b8bdf49fe455d2b46d7c3b.tar.bz2
cowboy-5964273cc4354b7378b8bdf49fe455d2b46d7c3b.zip
Fix the flushing of messages when switching to Websocket
We now flush messages that are specific to cowboy_http only. Stream handlers should also flush their own specific messages if necessary, although timeouts will be flushed regardless of where they originate from. Also renames the http_SUITE to old_http_SUITE to distinguish new tests from old tests. Most old tests need to be removed or converted eventually as they're legacy tests from Cowboy 1.0.
Diffstat (limited to 'test/handlers')
-rw-r--r--test/handlers/switch_protocol_flush_h.erl50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/handlers/switch_protocol_flush_h.erl b/test/handlers/switch_protocol_flush_h.erl
new file mode 100644
index 0000000..3d525ee
--- /dev/null
+++ b/test/handlers/switch_protocol_flush_h.erl
@@ -0,0 +1,50 @@
+%% This module is used to test the flushing of messages when
+%% switch_protocol is executed by cowboy_http.
+
+-module(switch_protocol_flush_h).
+
+-export([init/3]).
+-export([info/3]).
+-export([terminate/3]).
+-export([takeover/7]).
+-export([validate/1]).
+
+init(StreamID, Req, _) ->
+ Pid = list_to_pid(binary_to_list(cowboy_req:header(<<"x-test-pid">>, Req))),
+ %% Send ourselves a few messages that may or may not be flushed.
+ self() ! good,
+ self() ! {'EXIT', Pid, normal},
+ self() ! {system, a, b},
+ self() ! {{self(), StreamID}, hello},
+ self() ! {'$gen_call', a, b},
+ self() ! {timeout, make_ref(), ?MODULE},
+ self() ! {ranch_tcp, socket, <<"123">>},
+ {[{switch_protocol, #{}, ?MODULE, Pid}], undefined}.
+
+info(_, _, State) ->
+ {[], State}.
+
+terminate(_, _, _) ->
+ ok.
+
+takeover(_, _, _, _, _, _, Pid) ->
+ Msgs = receive_all([]),
+ Pid ! {Pid, Msgs},
+ exit(normal).
+
+receive_all(Acc) ->
+ receive
+ Msg ->
+ receive_all([Msg|Acc])
+ after 0 ->
+ Acc
+ end.
+
+validate(Msgs) ->
+ [
+ {ranch_tcp, socket, <<"123">>},
+ {'$gen_call', a, b},
+ {system, a, b},
+ good
+ ] = Msgs,
+ ok.