From 2b754e8a9c7e9ab10675349870f853cb7f394d15 Mon Sep 17 00:00:00 2001 From: hongliang <513918845@qq.com> Date: Thu, 26 Jul 2018 16:09:22 +0800 Subject: [PATCH 1/2] feature: add exported perl functions `add_global_init_processor` Signed-off-by: hongliang <513918845@qq.com> --- lib/Test/Nginx/Socket.pm | 2 +- lib/Test/Nginx/Util.pm | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Test/Nginx/Socket.pm b/lib/Test/Nginx/Socket.pm index 1d57b292..b3f557b2 100644 --- a/lib/Test/Nginx/Socket.pm +++ b/lib/Test/Nginx/Socket.pm @@ -38,7 +38,7 @@ our @EXPORT = qw( env_to_nginx is_str plan run_tests run_test server_name server_addr server_root html_dir server_port server_port_for_client timeout no_nginx_manager check_accum_error_log - add_block_preprocessor bail_out add_cleanup_handler + add_block_preprocessor add_global_init_processor bail_out add_cleanup_handler add_response_body_check ); diff --git a/lib/Test/Nginx/Util.pm b/lib/Test/Nginx/Util.pm index 085083a0..73f7dbf1 100644 --- a/lib/Test/Nginx/Util.pm +++ b/lib/Test/Nginx/Util.pm @@ -237,6 +237,7 @@ sub no_nginx_manager () { our @CleanupHandlers; our @BlockPreprocessors; +our @GlobalInitProcessors; sub bail_out (@); @@ -444,6 +445,7 @@ our @EXPORT = qw( $Benchmark $BenchmarkWarmup add_block_preprocessor + add_global_init_processor timeout worker_connections workers @@ -487,6 +489,10 @@ sub add_block_preprocessor(&) { unshift @BlockPreprocessors, shift; } +sub add_global_init_processor(&) { + unshift @GlobalInitProcessors, shift; +} + #our ($PrevRequest) our $PrevConfig; @@ -708,6 +714,10 @@ sub run_tests () { $ENV{TEST_NGINX_SERVER_PORT} = $ServerPort; } + for my $gi (@GlobalInitProcessors) { + $gi->(); + } + for my $block ($NoShuffle ? Test::Base::blocks() : shuffle Test::Base::blocks()) { for my $hdl (@BlockPreprocessors) { $hdl->($block); From 7ef7cff3bde804b8147ae99d1ef7f4ae9b936ccc Mon Sep 17 00:00:00 2001 From: hongliang <513918845@qq.com> Date: Thu, 26 Jul 2018 17:49:11 +0800 Subject: [PATCH 2/2] bugfix: remove duplicate `cleanup` function call Signed-off-by: hongliang <513918845@qq.com> --- lib/Test/Nginx/Util.pm | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Test/Nginx/Util.pm b/lib/Test/Nginx/Util.pm index 73f7dbf1..c723c685 100644 --- a/lib/Test/Nginx/Util.pm +++ b/lib/Test/Nginx/Util.pm @@ -2483,8 +2483,6 @@ retry: END { return if $InSubprocess; - cleanup(); - if ($UseStap || $UseValgrind || !$ENV{TEST_NGINX_NO_CLEAN}) { local $?; # to avoid confusing Test::Builder::_ending if (defined $PidFile && -f $PidFile) {