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' };
6 use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
8 my $srv = tcp_server();
9 open my $fh, '>', $u_conf;
13 stderr_path "$err_log"
14 timeout 3 # WORST FEATURE EVER
18 my $ar = unicorn(qw(-E none t/heartbeat-timeout.ru -c), $u_conf, { 3 => $srv });
20 my ($status, $hdr, $wpid) = do_req($srv, 'GET /pid HTTP/1.0');
21 like($status, qr!\AHTTP/1\.[01] 200\b!, 'PID request succeeds');
22 like($wpid, qr/\A[0-9]+\z/, 'worker is running');
24 my $t0 = clock_gettime(CLOCK_MONOTONIC);
25 my $c = tcp_start($srv, 'GET /block-forever HTTP/1.0');
26 vec(my $rvec = '', fileno($c), 1) = 1;
27 is(select($rvec, undef, undef, 6), 1, 'got readiness');
29 is(sysread($c, my $buf, 128), 0, 'got EOF response');
30 my $elapsed = clock_gettime(CLOCK_MONOTONIC) - $t0;
31 ok($elapsed > 3, 'timeout took >3s');
33 my @timeout_err = slurp($err_log);
34 truncate($err_log, 0);
35 is(grep(/timeout \(\d+s > 3s\), killing/, @timeout_err), 1,
36 'noted timeout error') or diag explain(\@timeout_err);
39 ($status, $hdr, my $new_pid) = do_req($srv, 'GET /pid HTTP/1.0');
40 like($status, qr!\AHTTP/1\.[01] 200\b!, 'PID request succeeds');
41 isnt($new_pid, $wpid, 'spawned new worker');
43 diag 'SIGSTOP for 4 seconds...';
48 ($status, $hdr, my $spid) = do_req($srv, 'GET /pid HTTP/1.0');
49 like($status, qr!\AHTTP/1\.[01] 200\b!,
50 "PID request succeeds #$i after STOP+CONT");
51 is($new_pid, $spid, "worker pid unchanged after STOP+CONT #$i");
53 diag 'sleeping 2s to ensure timeout is not delayed';