Dne Út 03.led.2012 16:03:11, landsidel.allen@gmail.com napsal(a):
Show quoted text> OS: FreeBSD 8.2-STABLE (Oct 14th, 2011)
> Platform: amd64
> Perl version: 5.12.4
> Mod version: Server-Starter-0.11 (install via CPAN "install
> Server::Starter" failing)
>
>
> One failing test:
> # Failed test 'status during restart'
> # at t/01-starter.t line 51.
> # '2:54944
> # '
> # doesn't match '(?s-xim:^1:\d+\n2:\d+$)'
>
There is similar bug in t/05-killolddelay.t. Attached patch fixes it.
From 046fb1328e76851a1398a624b77e746c37c62a67 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Thu, 21 Aug 2014 14:17:25 +0200
Subject: [PATCH] Synchronize to PID in t/05-killolddelay.t
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
There were races between various sleeps and the restarting server.
This patch fixes it by waiting for complete generation change in the
status file.
Similar to CPAN RT#73711.
Signed-off-by: Petr PÃsaÅ <ppisar@redhat.com>
---
t/05-killolddelay.t | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/t/05-killolddelay.t b/t/05-killolddelay.t
index 19856af..457bdd9 100644
--- a/t/05-killolddelay.t
+++ b/t/05-killolddelay.t
@@ -3,7 +3,7 @@ use warnings;
use File::Temp ();
use Test::TCP;
-use Test::More tests => 28;
+use Test::More tests => 26;
use Server::Starter qw(start_server);
@@ -45,17 +45,18 @@ for my $signal_on_hup ('TERM', 'USR1') {
$buf =~ /^(\d+):/;
my $worker_pid = $1;
# switch to next gen
- sleep 2;
- my $status = get_status();
- like(get_status(), qr/^1:\d+\n$/s, 'status before restart');
+ my $previous_generation = get_single_generation();
+ like($previous_generation, qr/^1:\d+\n$/s, 'status before restart');
kill 'HUP', $server_pid;
- sleep 4;
- like(get_status(), qr/^1:\d+\n2:\d+$/s, 'status during restart');
- # Child process has finished in 2 seconds but the parent
- # checks and calls waitpid every second, so wait for an
- # additional 1 second.
- sleep 3;
- like(get_status(), qr/^2:\d+\n$/s, 'status after restart');
+ my $current_generation;
+ while (($current_generation = get_single_generation()) eq
+ $previous_generation) {
+ sleep 1;
+ }
+ diag "Server changed from <$previous_generation> ",
+ "to <$current_generation>\n";
+
+ like($current_generation, qr/^2:\d+\n$/s, 'status after restart');
is(
do {
open my $fh, '<', "$tempdir/signame"
@@ -81,7 +82,20 @@ for my $signal_on_hup ('TERM', 'USR1') {
}
sub get_status {
+ while (! -e "$tempdir/status") {
+ sleep 1;
+ }
open my $fh, '<', "$tempdir/status"
or die "failed to open file:$tempdir/status:$!";
do { undef $/; <$fh> };
}
+
+sub get_single_generation {
+ my $status;
+ do {
+ sleep 1 if defined $status;
+ $status = get_status;
+ } until ($status =~ /\A\d+:\d+\n\z/);
+ chomp $status;
+ $status;
+}
--
1.9.3