diff options
author | Loïc Hoguin <[email protected]> | 2018-11-19 09:29:21 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-11-19 09:29:21 +0100 |
commit | d2f367fba3a44101ccc333d83ab0c889cca2317b (patch) | |
tree | f182a4ef949c9b93069d45a0cf4ea439d6ffb270 /test/misc_SUITE.erl | |
parent | bed328b6c9ce41782c340a89554599a838574d82 (diff) | |
download | cowboy-d2f367fba3a44101ccc333d83ab0c889cca2317b.tar.gz cowboy-d2f367fba3a44101ccc333d83ab0c889cca2317b.tar.bz2 cowboy-d2f367fba3a44101ccc333d83ab0c889cca2317b.zip |
Use try..after in tests that start their own listeners
Diffstat (limited to 'test/misc_SUITE.erl')
-rw-r--r-- | test/misc_SUITE.erl | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/test/misc_SUITE.erl b/test/misc_SUITE.erl index 4ad2325..45fb04e 100644 --- a/test/misc_SUITE.erl +++ b/test/misc_SUITE.erl @@ -82,25 +82,31 @@ set_env(Config0) -> Config = cowboy_test:init_http(?FUNCTION_NAME, #{ env => #{dispatch => []} }, Config0), - ConnPid1 = gun_open(Config), - Ref1 = gun:get(ConnPid1, "/"), - {response, _, 400, _} = gun:await(ConnPid1, Ref1), - cowboy:set_env(?FUNCTION_NAME, dispatch, init_dispatch(Config)), - %% Only new connections get the updated environment. - ConnPid2 = gun_open(Config), - Ref2 = gun:get(ConnPid2, "/"), - {response, _, 200, _} = gun:await(ConnPid2, Ref2), - ok. + try + ConnPid1 = gun_open(Config), + Ref1 = gun:get(ConnPid1, "/"), + {response, _, 400, _} = gun:await(ConnPid1, Ref1), + cowboy:set_env(?FUNCTION_NAME, dispatch, init_dispatch(Config)), + %% Only new connections get the updated environment. + ConnPid2 = gun_open(Config), + Ref2 = gun:get(ConnPid2, "/"), + {response, _, 200, _} = gun:await(ConnPid2, Ref2) + after + cowboy:stop_listener(?FUNCTION_NAME) + end. set_env_missing(Config0) -> doc("Live replace a middleware environment value when env was not provided."), Config = cowboy_test:init_http(?FUNCTION_NAME, #{}, Config0), - ConnPid1 = gun_open(Config), - Ref1 = gun:get(ConnPid1, "/"), - {response, _, 500, _} = gun:await(ConnPid1, Ref1), - cowboy:set_env(?FUNCTION_NAME, dispatch, []), - %% Only new connections get the updated environment. - ConnPid2 = gun_open(Config), - Ref2 = gun:get(ConnPid2, "/"), - {response, _, 400, _} = gun:await(ConnPid2, Ref2), - ok. + try + ConnPid1 = gun_open(Config), + Ref1 = gun:get(ConnPid1, "/"), + {response, _, 500, _} = gun:await(ConnPid1, Ref1), + cowboy:set_env(?FUNCTION_NAME, dispatch, []), + %% Only new connections get the updated environment. + ConnPid2 = gun_open(Config), + Ref2 = gun:get(ConnPid2, "/"), + {response, _, 400, _} = gun:await(ConnPid2, Ref2) + after + cowboy:stop_listener(?FUNCTION_NAME) + end. |