Skip to content

Commit

Permalink
Also test Websocket over HTTP/2
Browse files Browse the repository at this point in the history
It is much slower!!
  • Loading branch information
essen committed Dec 20, 2024
1 parent bee6d0a commit bb6faa1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
14 changes: 10 additions & 4 deletions test/cowboy_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,16 @@ common_all() ->
end.

common_groups(Tests) ->
Opts = case os:getenv("NO_PARALLEL") of
false -> [parallel];
_ -> []
Parallel = case os:getenv("NO_PARALLEL") of
false -> parallel;
_ -> no_parallel
end,
common_groups(Tests, Parallel).

common_groups(Tests, Parallel) ->
Opts = case Parallel of
parallel -> [parallel];
no_parallel -> []
end,
Groups = [
{http, Opts, Tests},
Expand All @@ -113,7 +120,6 @@ common_groups(Tests) ->
Groups
end.


init_common_groups(Name = http, Config, Mod) ->
init_http(Name, #{
env => #{dispatch => Mod:init_dispatch(Config)}
Expand Down
60 changes: 43 additions & 17 deletions test/ws_perf_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,63 @@

-import(ct_helper, [config/2]).
-import(ct_helper, [doc/1]).
-import(cowboy_test, [gun_open/1]).
-import(cowboy_test, [gun_open/2]).
-import(cowboy_test, [gun_down/1]).

%% ct.

all() ->
ct_helper:all(?MODULE).
[{group, http}, {group, h2c}].

init_per_suite(Config0) ->
Config = cowboy_test:init_http(?MODULE, #{
env => #{dispatch => init_dispatch()}
}, Config0),
groups() ->
cowboy_test:common_groups(ct_helper:all(?MODULE), no_parallel).

init_per_suite(Config) ->
{ok, LargeText} = file:read_file(filename:join(config(data_dir, Config), "grok_segond.txt")),
[{large_text, LargeText}|Config].

end_per_suite(_Config) ->
ok.

init_per_group(Name=http, Config) ->
ct:pal("Websocket over cleartext HTTP/1.1"),
cowboy_test:init_http(Name, #{
env => #{dispatch => init_dispatch(Config)}
}, [{flavor, vanilla}|Config]);
init_per_group(Name=h2c, Config) ->
ct:pal("Websocket over cleartext HTTP/2"),
Config1 = cowboy_test:init_http(Name, #{
enable_connect_protocol => true,
env => #{dispatch => init_dispatch(Config)},
max_frame_size_received => 1048576
}, [{flavor, vanilla}|Config]),
lists:keyreplace(protocol, 1, Config1, {protocol, http2}).

end_per_group(Name, _Config) ->
cowboy_test:stop_group(Name).

%% Dispatch configuration.

init_dispatch(_Config) ->
cowboy_router:compile([
{"localhost", [
{"/ws_echo", ws_echo, []}
]}
]).

%% Support functions for testing using Gun.

do_gun_open_ws(Config) ->
ConnPid = gun_open(Config),
ConnPid = gun_open(Config, #{http2_opts => #{
max_frame_size_received => 1048576,
notify_settings_changed => true
}}),
case config(protocol, Config) of
http -> ok;
http2 ->
{notify, settings_changed, #{enable_connect_protocol := true}}
= gun:await(ConnPid, undefined) %% @todo Maybe have a gun:await/1?
end,
StreamRef = gun:ws_upgrade(ConnPid, "/ws_echo"),
receive
{gun_upgrade, ConnPid, StreamRef, [<<"websocket">>], _} ->
Expand All @@ -56,19 +91,10 @@ receive_ws(ConnPid, StreamRef) ->
receive
{gun_ws, ConnPid, StreamRef, Frame} ->
{ok, Frame}
after 1000 ->
after 5000 ->
{error, timeout}
end.

%% Dispatch configuration.

init_dispatch() ->
cowboy_router:compile([
{"localhost", [
{"/ws_echo", ws_echo, []}
]}
]).

%% Tests.

one_binary_00064KiB(Config) ->
Expand Down

0 comments on commit bb6faa1

Please sign in to comment.