[perl-Server-Starter] Fix t/06-autorestart.t race

Petr Pisar ppisar at fedoraproject.org
Thu Jul 10 13:46:43 UTC 2014


commit eb4c9e9ca7f3d456982ce5195c5fb4ead9f077c1
Author: Petr Písař <ppisar at redhat.com>
Date:   Thu Jul 10 15:45:21 2014 +0200

    Fix t/06-autorestart.t race

 ...-Synchronize-to-PID-in-t-06-autorestart.t.patch |   83 ++++++++++++++++++++
 perl-Server-Starter.spec                           |    8 ++-
 2 files changed, 90 insertions(+), 1 deletions(-)
---
diff --git a/Server-Starter-0.17-Synchronize-to-PID-in-t-06-autorestart.t.patch b/Server-Starter-0.17-Synchronize-to-PID-in-t-06-autorestart.t.patch
new file mode 100644
index 0000000..9b4a713
--- /dev/null
+++ b/Server-Starter-0.17-Synchronize-to-PID-in-t-06-autorestart.t.patch
@@ -0,0 +1,83 @@
+From b2cee396fea96266a95a829b94cdf759d0eae76d Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar at redhat.com>
+Date: Thu, 10 Jul 2014 15:37:47 +0200
+Subject: [PATCH] Synchronize to PID in t/06-autorestart.t
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+There were races between various sleeps and 4s auto_restart_interval.
+This patch replaces the sleeps by waiting for status with a single PID
+entry.
+
+Similar to CPAN RT#73711.
+
+Signed-off-by: Petr Písař <ppisar at redhat.com>
+---
+ t/06-autorestart.t | 35 +++++++++++++++++++++++++++--------
+ 1 file changed, 27 insertions(+), 8 deletions(-)
+
+diff --git a/t/06-autorestart.t b/t/06-autorestart.t
+index bab9241..9401500 100644
+--- a/t/06-autorestart.t
++++ b/t/06-autorestart.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);
+ 
+@@ -46,13 +46,19 @@ 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 auto-restart');
+-            sleep 5;
+-            like(get_status(), qr/^1:\d+\n2:\d+$/s, 'status during transient state');
+-            sleep 4;
+-            like(get_status(), qr/^2:\d+\n$/s, 'status after auto-restart');
++            my $previous_generation = get_single_generation();
++            like($previous_generation, qr/^\d+:\d+\n$/s,
++                'status before auto-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/^\d+:\d+\n$/s,
++                'status after auto-restart');
+             is(
+                 do {
+                     open my $fh, '<', "$tempdir/signame"
+@@ -78,7 +84,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
+
diff --git a/perl-Server-Starter.spec b/perl-Server-Starter.spec
index 3d0cfc4..cb1b22b 100644
--- a/perl-Server-Starter.spec
+++ b/perl-Server-Starter.spec
@@ -1,6 +1,6 @@
 Name:           perl-Server-Starter
 Version:        0.17
-Release:        3%{?dist}
+Release:        4%{?dist}
 Summary:        Superdaemon for hot-deploying server programs
 License:        GPL+ or Artistic
 Group:          Development/Libraries
@@ -10,6 +10,8 @@ Source0:        http://www.cpan.org/authors/id/K/KA/KAZUHO/Server-Starter-%{vers
 Patch0:         Server-Starter-0.17-Synchronize-to-PID-in-t-07-envdir.t.patch
 # Fix loading the environment directory, bug #1100158, CPAN RT#73711
 Patch1:         Server-Starter-0.17-Fix-loading-envdir.patch
+# Fix t/06-autorestart.t race, bug #1100158, CPAN RT#73711
+Patch2:         Server-Starter-0.17-Synchronize-to-PID-in-t-06-autorestart.t.patch
 BuildArch:      noarch
 
 BuildRequires:  perl(ExtUtils::MakeMaker) >= 6.42
@@ -45,6 +47,7 @@ perl-Server-Starter's start_server script.
 %setup -q -n Server-Starter-%{version}
 %patch0 -p1
 %patch1 -p1
+%patch2 -p1
 
 %build
 # --skipdeps causes ExtUtils::AutoInstall not to try auto-installing
@@ -75,6 +78,9 @@ make test
 %{_mandir}/man1/start_server.*
 
 %changelog
+* Thu Jul 10 2014 Petr Pisar <ppisar at redhat.com> - 0.17-4
+- Fix t/06-autorestart.t race (bug #1100158)
+
 * Tue Jun 17 2014 Petr Pisar <ppisar at redhat.com> - 0.17-3
 - Fix races in t/07-envdir.t test (bug #1100158)
 - Load the environment directory just before restartin a server (bug #1100158)


More information about the scm-commits mailing list