diff options
author | Loïc Hoguin <[email protected]> | 2024-12-20 12:15:11 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2024-12-20 12:15:11 +0100 |
commit | bb6faa14a7ebb114f6f20064439018ab3fc87fbd (patch) | |
tree | d875b4b37ac18ff65a5bf7d9fc1aa9b5f29151ae | |
parent | bee6d0af9eecca7e2b26b83fc94dd70a1e6a986d (diff) | |
download | cowboy-optimise-websocket.tar.gz cowboy-optimise-websocket.tar.bz2 cowboy-optimise-websocket.zip |
Also test Websocket over HTTP/2optimise-websocket
It is much slower!!
-rw-r--r-- | test/cowboy_test.erl | 14 | ||||
-rw-r--r-- | test/ws_perf_SUITE.erl | 60 |
2 files changed, 53 insertions, 21 deletions
diff --git a/test/cowboy_test.erl b/test/cowboy_test.erl index 5a8fb13..670da18 100644 --- a/test/cowboy_test.erl +++ b/test/cowboy_test.erl @@ -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}, @@ -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)} diff --git a/test/ws_perf_SUITE.erl b/test/ws_perf_SUITE.erl index 890713d..4aa9e65 100644 --- a/test/ws_perf_SUITE.erl +++ b/test/ws_perf_SUITE.erl @@ -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">>], _} -> @@ -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) -> |