[Rt-commit] rt branch, 4.0/test-race-conditions, created. rt-4.0.0rc4-26-g6d51aa7
Alex Vandiver
alexmv at bestpractical.com
Sun Jan 30 16:06:23 EST 2011
The branch, 4.0/test-race-conditions has been created
at 6d51aa7291506ef1c2796348d0157f4ba45b6dcc (commit)
- Log -----------------------------------------------------------------
commit 6f7b0e46f8cb3d6fcc80260b3e219fb2e5d11035
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Sun Jan 30 15:44:09 2011 -0500
Prevent hangs during testing by removing a signals race condition
Under high load, such as heavily concurrent testing, there is no
guarantee that the parent process of the fork will have time to set up
the signal handler before the shild finishes initialization. Thus,
receiving a USR1 signal causes it to die, leaving a zombie child
process and the test wedged.
Set up the signal handler before we fork, which guarantees that the
child will not be able to force this race condition. It leaves forked
server processes with a USR1 signal handler, but there is little harm
to this.
diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index d0d465e..5354fcc 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1208,14 +1208,16 @@ sub start_plack_server {
kill 'USR1' => getppid();
});
+ # We are expecting a USR1 from the child process after it's ready
+ # to listen. We set this up _before_ we fork to avoid race
+ # conditions.
+ my $handled;
+ $SIG{USR1} = sub { $handled = 1};
+
my $pid = fork();
die "failed to fork" unless defined $pid;
if ($pid) {
- # We are expecting a USR1 from the child process after it's
- # ready to listen.
- my $handled;
- $SIG{USR1} = sub { $handled = 1};
sleep 15;
Test::More::diag "did not get expected USR1 for test server readiness"
unless $handled;
commit 6d51aa7291506ef1c2796348d0157f4ba45b6dcc
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Sun Jan 30 15:52:55 2011 -0500
Avoid sleeping for 15s if the server is already ready
It is possible for the server to have sent us the ready signal before
the parent hits the sleep(); in this case, the parent would wait,
uninterrupted by SIGUSR1, for 15s, despite the server being ready.
Hence, only sleep if we have not already received the signal. There
is still a minute race condition between the "unless" check and the
"sleep," but this reduces the window considerably, and the side
effects to the race condition are merely a slower test.
diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 5354fcc..1e4ca7c 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1218,7 +1218,7 @@ sub start_plack_server {
die "failed to fork" unless defined $pid;
if ($pid) {
- sleep 15;
+ sleep 15 unless $handled;
Test::More::diag "did not get expected USR1 for test server readiness"
unless $handled;
push @SERVERS, $pid;
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list