about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <BOFH@YHBT.net>2023-09-10 09:35:09 +0000
committerEric Wong <BOFH@YHBT.net>2023-09-10 19:55:13 +0000
commitdd9f2efeebf20cfa1def0ce92cb4e35a8b5c1580 (patch)
tree88aac55633ebfb5173eae2d9a8d152524321932f
parent948f78403172657590d690b9255467b9ccb968cd (diff)
downloadunicorn-dd9f2efeebf20cfa1def0ce92cb4e35a8b5c1580.tar.gz
The time(2) syscall use by CORE::time is inaccurate[1].
It's also easier to read `sleep 0.01' rather than the
longer `select' equivalent.

[1] a6463151bd1db5b9 (httpdate: favor gettimeofday(2) over time(2) for correctness, 2023-06-01)
-rw-r--r--t/active-unix-socket.t2
-rw-r--r--t/integration.t5
-rw-r--r--t/lib.perl4
-rw-r--r--t/reload-bad-config.t2
-rw-r--r--t/reopen-logs.t4
-rw-r--r--t/winch_ttin.t4
6 files changed, 10 insertions, 11 deletions
diff --git a/t/active-unix-socket.t b/t/active-unix-socket.t
index 32cb0c2..ff731b5 100644
--- a/t/active-unix-socket.t
+++ b/t/active-unix-socket.t
@@ -86,7 +86,7 @@ is($pidf, $to_kill{u1}, 'pid file contents unchanged after 2nd start failure');
                 'fail to connect to u1');
         for (1..50) { # wait for init process to reap worker
                 kill(0, $worker_pid) or last;
-                select(undef, undef, undef, 0.011);
+                sleep 0.011;
         }
         ok(!kill(0, $worker_pid), 'worker gone after parent dies');
 }
diff --git a/t/integration.t b/t/integration.t
index eb40ffc..80485e4 100644
--- a/t/integration.t
+++ b/t/integration.t
@@ -77,8 +77,9 @@ SKIP: { # Date header check
         eval { require HTTP::Date } or skip "HTTP::Date missing: $@", 1;
         $d[0] =~ s/^Date: //i or die 'BUG: did not strip date: prefix';
         my $t = HTTP::Date::str2time($d[0]);
-        ok($t >= $t0 && $t > 0 && $t <= time, 'valid date') or
-                diag(explain([$t, $!, \@d]));
+        my $now = time;
+        ok($t >= ($t0 - 1) && $t > 0 && $t <= ($now + 1), 'valid date') or
+                diag(explain(["t=$t t0=$t0 now=$now", $!, \@d]));
 };
 
 
diff --git a/t/lib.perl b/t/lib.perl
index 244972b..9254b23 100644
--- a/t/lib.perl
+++ b/t/lib.perl
@@ -6,7 +6,7 @@ use v5.14;
 use parent qw(Exporter);
 use autodie;
 use Test::More;
-use Time::HiRes qw(sleep);
+use Time::HiRes qw(sleep time);
 use IO::Socket::INET;
 use POSIX qw(dup2 _exit setpgid :signal_h SEEK_SET F_SETFD);
 use File::Temp 0.19 (); # 0.19 for ->newdir
@@ -15,7 +15,7 @@ our ($tmpdir, $errfh, $err_log, $u_sock, $u_conf, $daemon_pid,
 our @EXPORT = qw(unicorn slurp tcp_server tcp_start unicorn
         $tmpdir $errfh $err_log $u_sock $u_conf $daemon_pid $pid_file
         SEEK_SET tcp_host_port which spawn check_stderr unix_start slurp_hdr
-        do_req stop_daemon);
+        do_req stop_daemon sleep time);
 
 my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!);
 $tmpdir = File::Temp->newdir("unicorn-$base-XXXX", TMPDIR => 1);
diff --git a/t/reload-bad-config.t b/t/reload-bad-config.t
index 543421d..c023b88 100644
--- a/t/reload-bad-config.t
+++ b/t/reload-bad-config.t
@@ -38,7 +38,7 @@ my @l;
 for (1..1000) {
         @l = grep(/(?:done|error) reloading/, slurp($err_log)) and
                 last;
-        select undef, undef, undef, 0.011;
+        sleep 0.011;
 }
 diag slurp($err_log) if $ENV{V};
 ok(grep(/error reloading/, @l), 'got error reloading');
diff --git a/t/reopen-logs.t b/t/reopen-logs.t
index 8a58c1b..76a4dbd 100644
--- a/t/reopen-logs.t
+++ b/t/reopen-logs.t
@@ -23,8 +23,8 @@ rename($out_log, "$out_log.rot");
 $auto_reap->do_kill('USR1');
 
 my $tries = 1000;
-while (!-f $err_log && --$tries) { select undef, undef, undef, 0.01 };
-while (!-f $out_log && --$tries) { select undef, undef, undef, 0.01 };
+while (!-f $err_log && --$tries) { sleep 0.01 };
+while (!-f $out_log && --$tries) { sleep 0.01 };
 
 ok(-f $out_log, 'stdout_path recreated after USR1');
 ok(-f $err_log, 'stderr_path recreated after USR1');
diff --git a/t/winch_ttin.t b/t/winch_ttin.t
index 509b118..c507959 100644
--- a/t/winch_ttin.t
+++ b/t/winch_ttin.t
@@ -43,9 +43,7 @@ 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;
-}
+while (CORE::kill(0, $worker_pid) && --$tries) { sleep 0.01 }
 ok(!CORE::kill(0, $worker_pid), 'worker not running');
 
 ok(kill('TTIN', $pid), 'SIGTTIN to restart worker');