2 # Copyright (C) unicorn hackers <unicorn-public@yhbt.net>
3 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
4 use v5.14; BEGIN { require './t/lib.perl' };
7 my $ru = "$tmpdir/alt/config.ru";
8 open my $fh, '>', $u_conf;
12 stderr_path "$err_log"
13 working_directory "$tmpdir/alt" # the whole point of this test
14 before_fork { |_,_| \$master_ppid = Process.ppid }
18 my $common_ru = <<'EOM';
19 use Rack::ContentLength
20 use Rack::ContentType, 'text/plain'
21 run lambda { |env| [ 200, {}, [ "#{$master_ppid}\n" ] ] }
26 #\\--daemonize --listen $u_sock
31 unicorn('-c', $u_conf)->join; # will daemonize
32 chomp($daemon_pid = slurp($pid_file));
34 my ($status, $hdr, $bdy) = do_req($u_sock, 'GET / HTTP/1.0');
35 is($bdy, "1\n", 'got expected $master_ppid');
40 if ('test without CLI switches in config.ru') {
46 unicorn('-D', '-l', $u_sock, '-c', $u_conf)->join; # will daemonize
47 chomp($daemon_pid = slurp($pid_file));
49 ($status, $hdr, $bdy) = do_req($u_sock, 'GET / HTTP/1.0');
50 is($bdy, "1\n", 'got expected $master_ppid');
56 if ('ensures broken working_directory (missing config.ru) is OK') {
60 my $auto_reap = unicorn('-c', $u_conf);
62 isnt($?, 0, 'exited with error due to missing config.ru');
64 like(slurp($err_log), qr/rackup file \Q(config.ru)\E not readable/,
65 'noted unreadability of config.ru in stderr');
68 if ('fooapp.rb (not config.ru) works with working_directory') {
70 my $fooapp = "$tmpdir/alt/fooapp.rb";
71 open $fh, '>', $fooapp;
76 h = { 'content-type' => 'text/plain', 'content-length' => b.bytesize.to_s }
83 my $auto_reap = unicorn(qw(-c), $u_conf, qw(-I. fooapp.rb),
84 { -C => '/', 3 => $srv });
85 ($status, $hdr, $bdy) = do_req($srv, 'GET / HTTP/1.0');
86 is($bdy, "dir=$tmpdir/alt",
87 'fooapp.rb (w/o config.ru) w/ working_directory');
88 $auto_reap->join('TERM');
89 is($?, 0, 'fooapp.rb process exited');