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_conf = "$tmpdir/u.conf.rb";
8 my $u_sock = "$tmpdir/u.sock";
9 my $fifo = "$tmpdir/fifo";
10 mkfifo($fifo, 0666) or die "mkfifo($fifo): $!";
12 open my $fh, '>', $u_conf;
16 stderr_path "$err_log"
17 after_fork do |server, worker|
18 # test script will block while reading from $fifo,
19 File.open("$fifo", "wb") { |fp| fp.syswrite worker.nr.to_s }
24 unicorn('-D', '-c', $u_conf, 't/integration.ru')->join;
25 is($?, 0, 'daemonized properly');
26 open $fh, '<', "$tmpdir/pid";
27 chomp(my $pid = <$fh>);
28 ok(kill(0, $pid), 'daemonized PID works');
29 my $quit = sub { kill('QUIT', $pid) if $pid; $pid = undef };
33 my $worker_nr = <$fh>;
35 is($worker_nr, '0', 'initial worker spawned');
37 my ($status, $hdr, $worker_pid) = do_req($u_sock, 'GET /pid HTTP/1.0');
38 like($status, qr/ 200\b/, 'got 200 response');
39 like($worker_pid, qr/\A[0-9]+\n\z/s, 'PID in response');
41 ok(kill(0, $worker_pid), 'worker_pid is valid');
43 ok(kill('WINCH', $pid), 'SIGWINCH can be sent');
46 while (CORE::kill(0, $worker_pid) && --$tries) { sleep 0.01 }
47 ok(!CORE::kill(0, $worker_pid), 'worker not running');
49 ok(kill('TTIN', $pid), 'SIGTTIN to restart worker');
54 is($worker_nr, '0', 'worker restarted');
56 ($status, $hdr, my $new_worker_pid) = do_req($u_sock, 'GET /pid HTTP/1.0');
57 like($status, qr/ 200\b/, 'got 200 response');
58 like($new_worker_pid, qr/\A[0-9]+\n\z/, 'got new worker PID');
59 chomp $new_worker_pid;
60 ok(kill(0, $new_worker_pid), 'got a valid worker PID');
61 isnt($worker_pid, $new_worker_pid, 'worker PID changed');