1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
| | #!perl -w
# Copyright (C) unicorn hackers <unicorn-public@yhbt.net>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
use v5.14; BEGIN { require './t/lib.perl' };
use autodie;
mkdir "$tmpdir/alt";
my $ru = "$tmpdir/alt/config.ru";
open my $fh, '>', $u_conf;
print $fh <<EOM;
pid "$pid_file"
preload_app true
stderr_path "$err_log"
working_directory "$tmpdir/alt" # the whole point of this test
before_fork { |_,_| \$master_ppid = Process.ppid }
EOM
close $fh;
my $common_ru = <<'EOM';
use Rack::ContentLength
use Rack::ContentType, 'text/plain'
run lambda { |env| [ 200, {}, [ "#{$master_ppid}\n" ] ] }
EOM
open $fh, '>', $ru;
print $fh <<EOM;
#\\--daemonize --listen $u_sock
$common_ru
EOM
close $fh;
unicorn('-c', $u_conf)->join; # will daemonize
chomp($daemon_pid = slurp($pid_file));
my ($status, $hdr, $bdy) = do_req($u_sock, 'GET / HTTP/1.0');
is($bdy, "1\n", '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($daemon_pid = slurp($pid_file));
($status, $hdr, $bdy) = do_req($u_sock, 'GET / HTTP/1.0');
is($bdy, "1\n", '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 <<EOM;
class Fooapp
def self.call(env)
b = "dir=#{Dir.pwd}"
h = { 'content-type' => '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 });
($status, $hdr, $bdy) = do_req($srv, 'GET / HTTP/1.0');
is($bdy, "dir=$tmpdir/alt",
'fooapp.rb (w/o config.ru) w/ working_directory');
$auto_reap->join('TERM');
is($?, 0, 'fooapp.rb process exited');
check_stderr;
}
undef $tmpdir;
done_testing;
|