0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Add persistent_term support to the router

This commit is contained in:
Loïc Hoguin 2019-09-28 15:40:41 +02:00
parent 7bccad4d21
commit cf84f59d9b
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
5 changed files with 80 additions and 3 deletions

View file

@ -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}], #{