diff options
author | Loïc Hoguin <[email protected]> | 2014-04-26 13:46:55 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2014-04-26 13:46:55 +0200 |
commit | 980342f73c381413a09fbea94b43428e0f16d787 (patch) | |
tree | 9352716b2f5848d5c25049715a9f8fce3f88cb50 /test/cowboy_test.erl | |
parent | a3f7f68e30e97e907b230d14fe5d449c4fc8095c (diff) | |
download | cowboy-980342f73c381413a09fbea94b43428e0f16d787.tar.gz cowboy-980342f73c381413a09fbea94b43428e0f16d787.tar.bz2 cowboy-980342f73c381413a09fbea94b43428e0f16d787.zip |
Make loop handlers work with SPDY
Adds a loop_handler test suite that runs all tests under HTTP, HTTPS,
SPDY each with and without the compress option enabled.
Fixes output filtering that used to filter more than it should have.
This forces us to parse the string sent by the emulator, which means
it's probably not perfect yet. But it should at least not hide errors
we want to see.
Fix a crash in the output filtering code that entirely disabled
output. Now when there is a crash the normal tty output is restored.
Handlers are now in test/handlers/ as they can be reused between
suites.
Only generate a single certificate for the whole ct run to speed
things up when we got many different test groups each needing
certificates.
Diffstat (limited to 'test/cowboy_test.erl')
-rw-r--r-- | test/cowboy_test.erl | 76 |
1 files changed, 72 insertions, 4 deletions
diff --git a/test/cowboy_test.erl b/test/cowboy_test.erl index 4cb2a33..f4a5706 100644 --- a/test/cowboy_test.erl +++ b/test/cowboy_test.erl @@ -30,12 +30,32 @@ do_start(App) -> do_start(App) end. +%% SSL certificate creation and safekeeping. + +make_certs() -> + {_, Cert, Key} = ct_helper:make_certs(), + CertOpts = [{cert, Cert}, {key, Key}], + Pid = spawn(fun() -> receive after infinity -> ok end end), + ?MODULE = ets:new(?MODULE, [ordered_set, public, named_table, + {heir, Pid, undefined}]), + ets:insert(?MODULE, {cert_opts, CertOpts}), + ok. + +get_certs() -> + ets:lookup_element(?MODULE, cert_opts, 2). + %% Quick configuration value retrieval. config(Key, Config) -> {_, Value} = lists:keyfind(Key, 1, Config), Value. +%% Test case description. + +doc(String) -> + ct:comment(String), + ct:log(String). + %% List of all test cases in the suite. all(Suite) -> @@ -60,8 +80,7 @@ init_http(Ref, ProtoOpts, Config) -> [{type, tcp}, {port, Port}, {opts, []}|Config]. init_https(Ref, ProtoOpts, Config) -> - {_, Cert, Key} = ct_helper:make_certs(), - Opts = [{cert, Cert}, {key, Key}], + Opts = get_certs(), {ok, _} = cowboy:start_https(Ref, 100, Opts ++ [{port, 0}], [ {max_keepalive, 50}, {timeout, 500} @@ -70,13 +89,62 @@ init_https(Ref, ProtoOpts, Config) -> [{type, ssl}, {port, Port}, {opts, Opts}|Config]. init_spdy(Ref, ProtoOpts, Config) -> - {_, Cert, Key} = ct_helper:make_certs(), - Opts = [{cert, Cert}, {key, Key}], + Opts = get_certs(), {ok, _} = cowboy:start_spdy(Ref, 100, Opts ++ [{port, 0}], ProtoOpts), Port = ranch:get_port(Ref), [{type, ssl}, {port, Port}, {opts, Opts}|Config]. +%% Common group of listeners used by most suites. + +common_all() -> + [ + {group, http}, + {group, https}, + {group, spdy}, + {group, http_compress}, + {group, https_compress}, + {group, spdy_compress} + ]. + +common_groups(Tests) -> + [ + {http, [parallel], Tests}, + {https, [parallel], Tests}, + {spdy, [parallel], Tests}, + {http_compress, [parallel], Tests}, + {https_compress, [parallel], Tests}, + {spdy_compress, [parallel], Tests} + ]. + +init_common_groups(Name = http, Config, Mod) -> + init_http(Name, [ + {env, [{dispatch, Mod:init_dispatch(Config)}]} + ], Config); +init_common_groups(Name = https, Config, Mod) -> + init_https(Name, [ + {env, [{dispatch, Mod:init_dispatch(Config)}]} + ], Config); +init_common_groups(Name = spdy, Config, Mod) -> + init_spdy(Name, [ + {env, [{dispatch, Mod:init_dispatch(Config)}]} + ], Config); +init_common_groups(Name = http_compress, Config, Mod) -> + init_http(Name, [ + {env, [{dispatch, Mod:init_dispatch(Config)}]}, + {compress, true} + ], Config); +init_common_groups(Name = https_compress, Config, Mod) -> + init_https(Name, [ + {env, [{dispatch, Mod:init_dispatch(Config)}]}, + {compress, true} + ], Config); +init_common_groups(Name = spdy_compress, Config, Mod) -> + init_spdy(Name, [ + {env, [{dispatch, Mod:init_dispatch(Config)}]}, + {compress, true} + ], Config). + %% Support functions for testing using Gun. gun_open(Config) -> |