From f43c28ea10ca8d520b55f2fbb20710dd66fc4fb5 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 7 Sep 2023 22:55:09 +0000 Subject: [PATCH 01/11] tests: port some bad config tests to Perl 5 We can fold some tests into one test to save on Perl startup time (but Ruby startup time is a lost cause). --- t/lib.perl | 12 ++++---- t/reload-bad-config.t | 58 ++++++++++++++++++++++++++++++++++++ t/t0001-reload-bad-config.sh | 53 -------------------------------- t/t0002-config-conflict.sh | 49 ------------------------------ 4 files changed, 65 insertions(+), 107 deletions(-) create mode 100644 t/reload-bad-config.t delete mode 100755 t/t0001-reload-bad-config.sh delete mode 100755 t/t0002-config-conflict.sh diff --git a/t/lib.perl b/t/lib.perl index fe3404ba..7de9e426 100644 --- a/t/lib.perl +++ b/t/lib.perl @@ -9,17 +9,19 @@ use Test::More; use IO::Socket::INET; use POSIX qw(dup2 _exit setpgid :signal_h SEEK_SET F_SETFD); use File::Temp 0.19 (); # 0.19 for ->newdir -our ($tmpdir, $errfh); -our @EXPORT = qw(unicorn slurp tcp_server tcp_start unicorn $tmpdir $errfh +our ($tmpdir, $errfh, $err_log); +our @EXPORT = qw(unicorn slurp tcp_server tcp_start unicorn + $tmpdir $errfh $err_log SEEK_SET tcp_host_port which spawn check_stderr unix_start slurp_hdr); my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!); $tmpdir = File::Temp->newdir("unicorn-$base-XXXX", TMPDIR => 1); -open($errfh, '>>', "$tmpdir/err.log"); -END { diag slurp("$tmpdir/err.log") if $tmpdir }; +$err_log = "$tmpdir/err.log"; +open($errfh, '>>', $err_log); +END { diag slurp($err_log) if $tmpdir }; sub check_stderr () { - my @log = slurp("$tmpdir/err.log"); + my @log = slurp($err_log); diag("@log") if $ENV{V}; my @err = grep(!/NameError.*Unicorn::Waiter/, grep(/error/i, @log)); @err = grep(!/failed to set accept_filter=/, @err); diff --git a/t/reload-bad-config.t b/t/reload-bad-config.t new file mode 100644 index 00000000..c7055c7e --- /dev/null +++ b/t/reload-bad-config.t @@ -0,0 +1,58 @@ +#!perl -w +# Copyright (C) unicorn hackers +# License: GPL-3.0+ +use v5.14; BEGIN { require './t/lib.perl' }; +use autodie; +my $srv = tcp_server(); +my $host_port = tcp_host_port($srv); +my $ru = "$tmpdir/config.ru"; +my $u_conf = "$tmpdir/u.conf.rb"; + +open my $fh, '>', $ru; +print $fh <<'EOM'; +use Rack::ContentLength +use Rack::ContentType, 'text/plain' +config = ru = "hello world\n" # check for config variable conflicts, too +run lambda { |env| [ 200, {}, [ ru.to_s ] ] } +EOM +close $fh; + +open $fh, '>', $u_conf; +print $fh < $srv }); +my $c = tcp_start($srv, 'GET / HTTP/1.0'); +my ($status, $hdr) = slurp_hdr($c); +my $bdy = do { local $/; <$c> }; +like($status, qr!\AHTTP/1\.[01] 200\b!, 'status line valid at start'); +is($bdy, "hello world\n", 'body matches expected'); + +open $fh, '>>', $ru; +say $fh '....this better be a syntax error in any version of ruby...'; +close $fh; + +$ar->do_kill('HUP'); # reload +my @l; +for (1..1000) { + @l = grep(/(?:done|error) reloading/, slurp($err_log)) and + last; + select undef, undef, undef, 0.011; +} +diag slurp($err_log) if $ENV{V}; +ok(grep(/error reloading/, @l), 'got error reloading'); +open $fh, '>', $err_log; +close $fh; + +$c = tcp_start($srv, 'GET / HTTP/1.0'); +($status, $hdr) = slurp_hdr($c); +$bdy = do { local $/; <$c> }; +like($status, qr!\AHTTP/1\.[01] 200\b!, 'status line valid afte reload'); +is($bdy, "hello world\n", 'body matches expected after reload'); + +check_stderr; +undef $tmpdir; # quiet t/lib.perl END{} +done_testing; diff --git a/t/t0001-reload-bad-config.sh b/t/t0001-reload-bad-config.sh deleted file mode 100755 index 55bb3555..00000000 diff --git a/t/t0002-config-conflict.sh b/t/t0002-config-conflict.sh deleted file mode 100755 index d7b2181a..00000000