From d4514174ee7eadea89003f380acacf32d52acd9d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 7 Sep 2023 23:18:16 +0000 Subject: [PATCH 02/11] tests: port working_directory tests to Perl 5 We can fold a bunch of them into one test to save startup time, inodes, and FS activity. --- t/t0003-working_directory.sh | 51 --------- t/t0004-working_directory_broken.sh | 24 ----- t/t0005-working_directory_app.rb.sh | 40 ------- t/t0007-working_directory_no_embed_cli.sh | 44 -------- t/working_directory.t | 122 ++++++++++++++++++++++ 5 files changed, 122 insertions(+), 159 deletions(-) delete mode 100755 t/t0003-working_directory.sh delete mode 100755 t/t0004-working_directory_broken.sh delete mode 100755 t/t0005-working_directory_app.rb.sh delete mode 100755 t/t0007-working_directory_no_embed_cli.sh create mode 100644 t/working_directory.t diff --git a/t/t0003-working_directory.sh b/t/t0003-working_directory.sh deleted file mode 100755 index 79988d8b..00000000 diff --git a/t/t0004-working_directory_broken.sh b/t/t0004-working_directory_broken.sh deleted file mode 100755 index ca9d3825..00000000 diff --git a/t/t0005-working_directory_app.rb.sh b/t/t0005-working_directory_app.rb.sh deleted file mode 100755 index 0fbab4fc..00000000 diff --git a/t/t0007-working_directory_no_embed_cli.sh b/t/t0007-working_directory_no_embed_cli.sh deleted file mode 100755 index 77d67072..00000000 diff --git a/t/working_directory.t b/t/working_directory.t new file mode 100644 index 00000000..e7ff43a5 --- /dev/null +++ b/t/working_directory.t @@ -0,0 +1,122 @@ +#!perl -w +# Copyright (C) unicorn hackers +# License: GPL-3.0+ +use v5.14; BEGIN { require './t/lib.perl' }; +use autodie; +mkdir "$tmpdir/alt"; +my $u_sock = "$tmpdir/u.sock"; +my $ru = "$tmpdir/alt/config.ru"; +my $u_conf = "$tmpdir/u.conf.rb"; +open my $fh, '>', $u_conf; +print $fh <', $ru; +print $fh <(1) if defined $pid }; + +unicorn('-c', $u_conf)->join; # will daemonize +chomp($pid = slurp("$tmpdir/pid")); + +my $c = unix_start($u_sock, 'GET / HTTP/1.0'); +my ($status, $hdr) = slurp_hdr($c); +chomp(my $bdy = do { local $/; <$c> }); +is($bdy, 1, 'got expected $master_ppid'); + +$stop_daemon->(); +check_stderr; + +if ('test without CLI switches in config.ru') { + truncate $err_log, 0; + open $fh, '>', $ru; + print $fh $common_ru; + close $fh; + + unicorn('-D', '-l', $u_sock, '-c', $u_conf)->join; # will daemonize + chomp($pid = slurp("$tmpdir/pid")); + + $c = unix_start($u_sock, 'GET / HTTP/1.0'); + ($status, $hdr) = slurp_hdr($c); + chomp($bdy = do { local $/; <$c> }); + is($bdy, 1, 'got expected $master_ppid'); + + $stop_daemon->(); + check_stderr; +} + +if ('ensures broken working_directory (missing config.ru) is OK') { + truncate $err_log, 0; + unlink $ru; + + my $auto_reap = unicorn('-c', $u_conf); + $auto_reap->join; + isnt($?, 0, 'exited with error due to missing config.ru'); + + like(slurp($err_log), qr/rackup file \Q(config.ru)\E not readable/, + 'noted unreadability of config.ru in stderr'); +} + +if ('fooapp.rb (not config.ru) works with working_directory') { + truncate $err_log, 0; + my $fooapp = "$tmpdir/alt/fooapp.rb"; + open $fh, '>', $fooapp; + print $fh < 'text/plain', 'content-length' => b.bytesize.to_s } + [ 200, h, [ b ] ] + end +end +EOM + close $fh; + my $srv = tcp_server; + my $auto_reap = unicorn(qw(-c), $u_conf, qw(-I. fooapp.rb), + { -C => '/', 3 => $srv }); + $c = tcp_start($srv, 'GET / HTTP/1.0'); + ($status, $hdr) = slurp_hdr($c); + chomp($bdy = do { local $/; <$c> }); + is($bdy, "dir=$tmpdir/alt", + 'fooapp.rb (w/o config.ru) w/ working_directory'); + close $c; + $auto_reap->join('TERM'); + is($?, 0, 'fooapp.rb process exited'); + check_stderr; +} + +undef $tmpdir; +done_testing;