From 86aea575c331a3b5242db1c14a848928a37ff9e3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 10 Sep 2023 08:27:04 +0000 Subject: [PATCH 05/11] tests: rewrite SIGWINCH && SIGTTIN test in Perl 5 No need to deal with full second sleeps, here. --- t/t0009-winch_ttin.sh | 59 ----------------------------------- t/winch_ttin.t | 72 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 59 deletions(-) delete mode 100755 t/t0009-winch_ttin.sh create mode 100644 t/winch_ttin.t diff --git a/t/t0009-winch_ttin.sh b/t/t0009-winch_ttin.sh deleted file mode 100755 index 6e56e30c..00000000 diff --git a/t/winch_ttin.t b/t/winch_ttin.t new file mode 100644 index 00000000..1a198778 --- /dev/null +++ b/t/winch_ttin.t @@ -0,0 +1,72 @@ +#!perl -w +# Copyright (C) unicorn hackers +# License: GPL-3.0+ +use v5.14; BEGIN { require './t/lib.perl' }; +use autodie; +use POSIX qw(mkfifo); +my $u_conf = "$tmpdir/u.conf.rb"; +my $u_sock = "$tmpdir/u.sock"; +my $fifo = "$tmpdir/fifo"; +mkfifo($fifo, 0666) or die "mkfifo($fifo): $!"; + +open my $fh, '>', $u_conf; +print $fh <join; +is($?, 0, 'daemonized properly'); +open $fh, '<', "$tmpdir/pid"; +chomp(my $pid = <$fh>); +ok(kill(0, $pid), 'daemonized PID works'); +my $quit = sub { kill('QUIT', $pid) if $pid; $pid = undef }; +END { $quit->() }; + +open $fh, '<', $fifo; +my $worker_nr = <$fh>; +close $fh; +is($worker_nr, '0', 'initial worker spawned'); + +my $c = unix_start($u_sock, 'GET /pid HTTP/1.0'); +my ($status, $hdr) = slurp_hdr($c); +like($status, qr/ 200\b/, 'got 200 response'); +my $worker_pid = do { local $/; <$c> }; +like($worker_pid, qr/\A[0-9]+\n\z/s, 'PID in response'); +chomp $worker_pid; +ok(kill(0, $worker_pid), 'worker_pid is valid'); + +ok(kill('WINCH', $pid), 'SIGWINCH can be sent'); + +my $tries = 1000; +while (CORE::kill(0, $worker_pid) && --$tries) { + select undef, undef, undef, 0.01; +} +ok(!CORE::kill(0, $worker_pid), 'worker not running'); + +ok(kill('TTIN', $pid), 'SIGTTIN to restart worker'); + +open $fh, '<', $fifo; +$worker_nr = <$fh>; +close $fh; +is($worker_nr, '0', 'worker restarted'); + +$c = unix_start($u_sock, 'GET /pid HTTP/1.0'); +($status, $hdr) = slurp_hdr($c); +like($status, qr/ 200\b/, 'got 200 response'); +chomp(my $new_worker_pid = do { local $/; <$c> }); +like($new_worker_pid, qr/\A[0-9]+\z/, 'got new worker PID'); +ok(kill(0, $new_worker_pid), 'got a valid worker PID'); +isnt($worker_pid, $new_worker_pid, 'worker PID changed'); + +$quit->(); + +check_stderr; +undef $tmpdir; +done_testing;