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 $u_sock = "$tmpdir/u.sock";
8 my $ru = "$tmpdir/alt/config.ru";
9 my $u_conf = "$tmpdir/u.conf.rb";
10 open my $fh, '>', $u_conf;
14 stderr_path "$err_log"
15 working_directory "$tmpdir/alt" # the whole point of this test
16 before_fork { |_,_| \$master_ppid = Process.ppid }
20 my $common_ru = <<'EOM';
21 use Rack::ContentLength
22 use Rack::ContentType, 'text/plain'
23 run lambda { |env| [ 200, {}, [ "#{$master_ppid}\n" ] ] }
28 #\\--daemonize --listen $u_sock
34 my $stop_daemon = sub {
38 while (CORE::kill(0, $pid) && --$tries) {
39 select undef, undef, undef, 0.01;
41 if ($is_END && CORE::kill(0, $pid)) {
42 CORE::kill('KILL', $pid);
43 die "daemonized PID=$pid did not die";
45 ok(!CORE::kill(0, $pid), 'daemonized unicorn gone');
50 END { $stop_daemon->(1) if defined $pid };
52 unicorn('-c', $u_conf)->join; # will daemonize
53 chomp($pid = slurp("$tmpdir/pid"));
55 my $c = unix_start($u_sock, 'GET / HTTP/1.0');
56 my ($status, $hdr) = slurp_hdr($c);
57 chomp(my $bdy = do { local $/; <$c> });
58 is($bdy, 1, 'got expected $master_ppid');
63 if ('test without CLI switches in config.ru') {
69 unicorn('-D', '-l', $u_sock, '-c', $u_conf)->join; # will daemonize
70 chomp($pid = slurp("$tmpdir/pid"));
72 $c = unix_start($u_sock, 'GET / HTTP/1.0');
73 ($status, $hdr) = slurp_hdr($c);
74 chomp($bdy = do { local $/; <$c> });
75 is($bdy, 1, 'got expected $master_ppid');
81 if ('ensures broken working_directory (missing config.ru) is OK') {
85 my $auto_reap = unicorn('-c', $u_conf);
87 isnt($?, 0, 'exited with error due to missing config.ru');
89 like(slurp($err_log), qr/rackup file \Q(config.ru)\E not readable/,
90 'noted unreadability of config.ru in stderr');
93 if ('fooapp.rb (not config.ru) works with working_directory') {
95 my $fooapp = "$tmpdir/alt/fooapp.rb";
96 open $fh, '>', $fooapp;
101 h = { 'content-type' => 'text/plain', 'content-length' => b.bytesize.to_s }
107 my $srv = tcp_server;
108 my $auto_reap = unicorn(qw(-c), $u_conf, qw(-I. fooapp.rb),
109 { -C => '/', 3 => $srv });
110 $c = tcp_start($srv, 'GET / HTTP/1.0');
111 ($status, $hdr) = slurp_hdr($c);
112 chomp($bdy = do { local $/; <$c> });
113 is($bdy, "dir=$tmpdir/alt",
114 'fooapp.rb (w/o config.ru) w/ working_directory');
116 $auto_reap->join('TERM');
117 is($?, 0, 'fooapp.rb process exited');