mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Reorganize the websocket test suite
We now have the suite specific modules in the data folder. Compilation is performed by the Makefile instead of ct_run.
This commit is contained in:
parent
cf0e005894
commit
2e91677723
11 changed files with 58 additions and 25 deletions
13
Makefile
13
Makefile
|
@ -21,7 +21,8 @@ erlc_verbose = $(erlc_verbose_$(V))
|
||||||
gen_verbose_0 = @echo " GEN " $@;
|
gen_verbose_0 = @echo " GEN " $@;
|
||||||
gen_verbose = $(gen_verbose_$(V))
|
gen_verbose = $(gen_verbose_$(V))
|
||||||
|
|
||||||
.PHONY: all clean-all app clean deps clean-deps docs clean-docs tests autobahn build-plt dialyze
|
.PHONY: all clean-all app clean deps clean-deps docs clean-docs \
|
||||||
|
build-tests tests autobahn build-plt dialyze
|
||||||
|
|
||||||
# Application.
|
# Application.
|
||||||
|
|
||||||
|
@ -71,7 +72,12 @@ clean-docs:
|
||||||
|
|
||||||
# Tests.
|
# Tests.
|
||||||
|
|
||||||
|
build-tests:
|
||||||
|
$(gen_verbose) erlc -v $(ERLC_OPTS) \
|
||||||
|
-o test/ test/*.erl test/*/*.erl -pa ebin/
|
||||||
|
|
||||||
CT_RUN = ct_run \
|
CT_RUN = ct_run \
|
||||||
|
-no_auto_compile \
|
||||||
-noshell \
|
-noshell \
|
||||||
-pa ebin $(DEPS_DIR)/*/ebin \
|
-pa ebin $(DEPS_DIR)/*/ebin \
|
||||||
-dir test \
|
-dir test \
|
||||||
|
@ -79,11 +85,12 @@ CT_RUN = ct_run \
|
||||||
# -cover test/cover.spec
|
# -cover test/cover.spec
|
||||||
|
|
||||||
tests: ERLC_OPTS += -DTEST=1
|
tests: ERLC_OPTS += -DTEST=1
|
||||||
tests: clean clean-deps deps app
|
tests: clean clean-deps deps app build-tests
|
||||||
@mkdir -p logs/
|
@mkdir -p logs/
|
||||||
@$(CT_RUN) -suite eunit_SUITE http_SUITE ws_SUITE
|
@$(CT_RUN) -suite eunit_SUITE http_SUITE ws_SUITE
|
||||||
|
$(gen_verbose) rm -f test/*.beam
|
||||||
|
|
||||||
autobahn: clean clean-deps deps app
|
autobahn: clean clean-deps deps app build-tests
|
||||||
@mkdir -p logs/
|
@mkdir -p logs/
|
||||||
@$(CT_RUN) -suite autobahn_SUITE
|
@$(CT_RUN) -suite autobahn_SUITE
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ end_per_group(Listener, _Config) ->
|
||||||
|
|
||||||
init_dispatch() ->
|
init_dispatch() ->
|
||||||
cowboy_router:compile([{"localhost", [
|
cowboy_router:compile([{"localhost", [
|
||||||
{"/echo", websocket_echo_handler, []}]}]).
|
{"/echo", autobahn_echo, []}]}]).
|
||||||
|
|
||||||
%% autobahn cases
|
%% autobahn cases
|
||||||
|
|
||||||
|
|
26
test/autobahn_SUITE_data/autobahn_echo.erl
Normal file
26
test/autobahn_SUITE_data/autobahn_echo.erl
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
%% Feel free to use, reuse and abuse the code in this file.
|
||||||
|
|
||||||
|
-module(autobahn_echo).
|
||||||
|
-behaviour(cowboy_websocket_handler).
|
||||||
|
-export([init/3]).
|
||||||
|
-export([websocket_init/3, websocket_handle/3,
|
||||||
|
websocket_info/3, websocket_terminate/3]).
|
||||||
|
|
||||||
|
init(_Any, _Req, _Opts) ->
|
||||||
|
{upgrade, protocol, cowboy_websocket}.
|
||||||
|
|
||||||
|
websocket_init(_TransportName, Req, _Opts) ->
|
||||||
|
{ok, Req, undefined}.
|
||||||
|
|
||||||
|
websocket_handle({text, Data}, Req, State) ->
|
||||||
|
{reply, {text, Data}, Req, State};
|
||||||
|
websocket_handle({binary, Data}, Req, State) ->
|
||||||
|
{reply, {binary, Data}, Req, State};
|
||||||
|
websocket_handle(_Frame, Req, State) ->
|
||||||
|
{ok, Req, State}.
|
||||||
|
|
||||||
|
websocket_info(_Info, Req, State) ->
|
||||||
|
{ok, Req, State}.
|
||||||
|
|
||||||
|
websocket_terminate(_Reason, _Req, _State) ->
|
||||||
|
ok.
|
|
@ -90,30 +90,30 @@ end_per_group(Listener, _Config) ->
|
||||||
init_dispatch() ->
|
init_dispatch() ->
|
||||||
cowboy_router:compile([
|
cowboy_router:compile([
|
||||||
{"localhost", [
|
{"localhost", [
|
||||||
{"/websocket", websocket_handler, []},
|
{"/ws_echo_timer", ws_echo_timer, []},
|
||||||
{"/ws_echo_handler", websocket_echo_handler, []},
|
{"/ws_echo", ws_echo, []},
|
||||||
{"/ws_init_shutdown", websocket_handler_init_shutdown, []},
|
{"/ws_init_shutdown", ws_init_shutdown, []},
|
||||||
{"/ws_send_many", ws_send_many_handler, [
|
{"/ws_send_many", ws_send_many, [
|
||||||
{sequence, [
|
{sequence, [
|
||||||
{text, <<"one">>},
|
{text, <<"one">>},
|
||||||
{text, <<"two">>},
|
{text, <<"two">>},
|
||||||
{text, <<"seven!">>}]}
|
{text, <<"seven!">>}]}
|
||||||
]},
|
]},
|
||||||
{"/ws_send_close", ws_send_many_handler, [
|
{"/ws_send_close", ws_send_many, [
|
||||||
{sequence, [
|
{sequence, [
|
||||||
{text, <<"send">>},
|
{text, <<"send">>},
|
||||||
close,
|
close,
|
||||||
{text, <<"won't be received">>}]}
|
{text, <<"won't be received">>}]}
|
||||||
]},
|
]},
|
||||||
{"/ws_send_close_payload", ws_send_many_handler, [
|
{"/ws_send_close_payload", ws_send_many, [
|
||||||
{sequence, [
|
{sequence, [
|
||||||
{text, <<"send">>},
|
{text, <<"send">>},
|
||||||
{close, 1001, <<"some text!">>},
|
{close, 1001, <<"some text!">>},
|
||||||
{text, <<"won't be received">>}]}
|
{text, <<"won't be received">>}]}
|
||||||
]},
|
]},
|
||||||
{"/ws_timeout_hibernate", ws_timeout_hibernate_handler, []},
|
{"/ws_timeout_hibernate", ws_timeout_hibernate, []},
|
||||||
{"/ws_timeout_cancel", ws_timeout_cancel_handler, []},
|
{"/ws_timeout_cancel", ws_timeout_cancel, []},
|
||||||
{"/ws_upgrade_with_opts", ws_upgrade_with_opts_handler,
|
{"/ws_upgrade_with_opts", ws_upgrade_with_opts,
|
||||||
<<"failure">>}
|
<<"failure">>}
|
||||||
]}
|
]}
|
||||||
]).
|
]).
|
||||||
|
@ -126,7 +126,7 @@ ws0(Config) ->
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
||||||
[binary, {active, false}, {packet, raw}]),
|
[binary, {active, false}, {packet, raw}]),
|
||||||
ok = gen_tcp:send(Socket,
|
ok = gen_tcp:send(Socket,
|
||||||
"GET /websocket HTTP/1.1\r\n"
|
"GET /ws_echo_timer HTTP/1.1\r\n"
|
||||||
"Host: localhost\r\n"
|
"Host: localhost\r\n"
|
||||||
"Connection: Upgrade\r\n"
|
"Connection: Upgrade\r\n"
|
||||||
"Upgrade: WebSocket\r\n"
|
"Upgrade: WebSocket\r\n"
|
||||||
|
@ -143,7 +143,7 @@ ws8(Config) ->
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
||||||
[binary, {active, false}, {packet, raw}]),
|
[binary, {active, false}, {packet, raw}]),
|
||||||
ok = gen_tcp:send(Socket, [
|
ok = gen_tcp:send(Socket, [
|
||||||
"GET /websocket HTTP/1.1\r\n"
|
"GET /ws_echo_timer HTTP/1.1\r\n"
|
||||||
"Host: localhost\r\n"
|
"Host: localhost\r\n"
|
||||||
"Connection: Upgrade\r\n"
|
"Connection: Upgrade\r\n"
|
||||||
"Upgrade: websocket\r\n"
|
"Upgrade: websocket\r\n"
|
||||||
|
@ -203,7 +203,7 @@ ws8_single_bytes(Config) ->
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
||||||
[binary, {active, false}, {packet, raw}]),
|
[binary, {active, false}, {packet, raw}]),
|
||||||
ok = gen_tcp:send(Socket, [
|
ok = gen_tcp:send(Socket, [
|
||||||
"GET /websocket HTTP/1.1\r\n"
|
"GET /ws_echo_timer HTTP/1.1\r\n"
|
||||||
"Host: localhost\r\n"
|
"Host: localhost\r\n"
|
||||||
"Connection: Upgrade\r\n"
|
"Connection: Upgrade\r\n"
|
||||||
"Upgrade: websocket\r\n"
|
"Upgrade: websocket\r\n"
|
||||||
|
@ -263,7 +263,7 @@ ws13(Config) ->
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
||||||
[binary, {active, false}, {packet, raw}]),
|
[binary, {active, false}, {packet, raw}]),
|
||||||
ok = gen_tcp:send(Socket, [
|
ok = gen_tcp:send(Socket, [
|
||||||
"GET /websocket HTTP/1.1\r\n"
|
"GET /ws_echo_timer HTTP/1.1\r\n"
|
||||||
"Host: localhost\r\n"
|
"Host: localhost\r\n"
|
||||||
"Connection: Upgrade\r\n"
|
"Connection: Upgrade\r\n"
|
||||||
"Origin: http://localhost\r\n"
|
"Origin: http://localhost\r\n"
|
||||||
|
@ -404,7 +404,7 @@ ws_text_fragments(Config) ->
|
||||||
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
{ok, Socket} = gen_tcp:connect("localhost", Port,
|
||||||
[binary, {active, false}, {packet, raw}]),
|
[binary, {active, false}, {packet, raw}]),
|
||||||
ok = gen_tcp:send(Socket, [
|
ok = gen_tcp:send(Socket, [
|
||||||
"GET /ws_echo_handler HTTP/1.1\r\n"
|
"GET /ws_echo HTTP/1.1\r\n"
|
||||||
"Host: localhost\r\n"
|
"Host: localhost\r\n"
|
||||||
"Connection: Upgrade\r\n"
|
"Connection: Upgrade\r\n"
|
||||||
"Upgrade: websocket\r\n"
|
"Upgrade: websocket\r\n"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
%% Feel free to use, reuse and abuse the code in this file.
|
%% Feel free to use, reuse and abuse the code in this file.
|
||||||
|
|
||||||
-module(websocket_echo_handler).
|
-module(ws_echo).
|
||||||
-behaviour(cowboy_websocket_handler).
|
-behaviour(cowboy_websocket_handler).
|
||||||
-export([init/3]).
|
-export([init/3]).
|
||||||
-export([websocket_init/3, websocket_handle/3,
|
-export([websocket_init/3, websocket_handle/3,
|
|
@ -1,6 +1,6 @@
|
||||||
%% Feel free to use, reuse and abuse the code in this file.
|
%% Feel free to use, reuse and abuse the code in this file.
|
||||||
|
|
||||||
-module(websocket_handler).
|
-module(ws_echo_timer).
|
||||||
-behaviour(cowboy_websocket_handler).
|
-behaviour(cowboy_websocket_handler).
|
||||||
-export([init/3]).
|
-export([init/3]).
|
||||||
-export([websocket_init/3, websocket_handle/3,
|
-export([websocket_init/3, websocket_handle/3,
|
|
@ -1,6 +1,6 @@
|
||||||
%% Feel free to use, reuse and abuse the code in this file.
|
%% Feel free to use, reuse and abuse the code in this file.
|
||||||
|
|
||||||
-module(websocket_handler_init_shutdown).
|
-module(ws_init_shutdown).
|
||||||
-behaviour(cowboy_websocket_handler).
|
-behaviour(cowboy_websocket_handler).
|
||||||
-export([init/3]).
|
-export([init/3]).
|
||||||
-export([websocket_init/3, websocket_handle/3,
|
-export([websocket_init/3, websocket_handle/3,
|
|
@ -1,6 +1,6 @@
|
||||||
%% Feel free to use, reuse and abuse the code in this file.
|
%% Feel free to use, reuse and abuse the code in this file.
|
||||||
|
|
||||||
-module(ws_send_many_handler).
|
-module(ws_send_many).
|
||||||
-behaviour(cowboy_websocket_handler).
|
-behaviour(cowboy_websocket_handler).
|
||||||
|
|
||||||
-export([init/3]).
|
-export([init/3]).
|
|
@ -1,6 +1,6 @@
|
||||||
%% Feel free to use, reuse and abuse the code in this file.
|
%% Feel free to use, reuse and abuse the code in this file.
|
||||||
|
|
||||||
-module(ws_timeout_cancel_handler).
|
-module(ws_timeout_cancel).
|
||||||
-behaviour(cowboy_websocket_handler).
|
-behaviour(cowboy_websocket_handler).
|
||||||
-export([init/3]).
|
-export([init/3]).
|
||||||
-export([websocket_init/3, websocket_handle/3,
|
-export([websocket_init/3, websocket_handle/3,
|
|
@ -1,6 +1,6 @@
|
||||||
%% Feel free to use, reuse and abuse the code in this file.
|
%% Feel free to use, reuse and abuse the code in this file.
|
||||||
|
|
||||||
-module(ws_timeout_hibernate_handler).
|
-module(ws_timeout_hibernate).
|
||||||
-behaviour(cowboy_websocket_handler).
|
-behaviour(cowboy_websocket_handler).
|
||||||
-export([init/3]).
|
-export([init/3]).
|
||||||
-export([websocket_init/3, websocket_handle/3,
|
-export([websocket_init/3, websocket_handle/3,
|
|
@ -1,6 +1,6 @@
|
||||||
%% Feel free to use, reuse and abuse the code in this file.
|
%% Feel free to use, reuse and abuse the code in this file.
|
||||||
|
|
||||||
-module(ws_upgrade_with_opts_handler).
|
-module(ws_upgrade_with_opts).
|
||||||
-behaviour(cowboy_websocket_handler).
|
-behaviour(cowboy_websocket_handler).
|
||||||
|
|
||||||
-export([init/3]).
|
-export([init/3]).
|
Loading…
Add table
Add a link
Reference in a new issue