From cf84f59d9bdf819d943b3de8e3bc85c561f88efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 28 Sep 2019 15:40:41 +0200 Subject: Add persistent_term support to the router --- test/http2_SUITE.erl | 23 +++++++++++++++++++++++ test/http_SUITE.erl | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) (limited to 'test') diff --git a/test/http2_SUITE.erl b/test/http2_SUITE.erl index 3af837b..44fc5cc 100644 --- a/test/http2_SUITE.erl +++ b/test/http2_SUITE.erl @@ -196,6 +196,29 @@ max_frame_size_sent(Config) -> cowboy:stop_listener(?FUNCTION_NAME) end. +persistent_term_router(Config) -> + doc("The router can retrieve the routes from persistent_term storage."), + case erlang:function_exported(persistent_term, get, 1) of + true -> do_persistent_term_router(Config); + false -> {skip, "This test uses the persistent_term functionality added in Erlang/OTP 21.2."} + end. + +do_persistent_term_router(Config) -> + persistent_term:put(?FUNCTION_NAME, init_dispatch(Config)), + {ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], #{ + env => #{dispatch => {persistent_term, ?FUNCTION_NAME}} + }), + Port = ranch:get_port(?FUNCTION_NAME), + try + ConnPid = gun_open([{type, tcp}, {protocol, http2}, {port, Port}|Config]), + {ok, http2} = gun:await_up(ConnPid), + StreamRef = gun:get(ConnPid, "/"), + {response, nofin, 200, _} = gun:await(ConnPid, StreamRef), + gun:close(ConnPid) + after + cowboy:stop_listener(?FUNCTION_NAME) + end. + preface_timeout_infinity(Config) -> doc("Ensure infinity for preface_timeout is accepted."), ProtoOpts = #{ diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl index 7f23da4..0b4edd9 100644 --- a/test/http_SUITE.erl +++ b/test/http_SUITE.erl @@ -250,6 +250,29 @@ idle_timeout_infinity(Config) -> cowboy:stop_listener(?FUNCTION_NAME) end. +persistent_term_router(Config) -> + doc("The router can retrieve the routes from persistent_term storage."), + case erlang:function_exported(persistent_term, get, 1) of + true -> do_persistent_term_router(Config); + false -> {skip, "This test uses the persistent_term functionality added in Erlang/OTP 21.2."} + end. + +do_persistent_term_router(Config) -> + persistent_term:put(?FUNCTION_NAME, init_dispatch(Config)), + {ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], #{ + env => #{dispatch => {persistent_term, ?FUNCTION_NAME}} + }), + Port = ranch:get_port(?FUNCTION_NAME), + try + ConnPid = gun_open([{type, tcp}, {protocol, http}, {port, Port}|Config]), + {ok, http} = gun:await_up(ConnPid), + StreamRef = gun:get(ConnPid, "/"), + {response, nofin, 200, _} = gun:await(ConnPid, StreamRef), + gun:close(ConnPid) + after + cowboy:stop_listener(?FUNCTION_NAME) + end. + request_timeout_infinity(Config) -> doc("Ensure the request_timeout option accepts the infinity value."), {ok, _} = cowboy:start_clear(?FUNCTION_NAME, [{port, 0}], #{ -- cgit v1.2.3