Force t/io/openpid.t to use the alarm() watchdog strategy.
authorGeorge Greer <perl@greerga.m-l.org>
Sun, 4 Jul 2010 05:20:53 +0000 (01:20 -0400)
committerRafael Garcia-Suarez <rgs@consttype.org>
Sun, 4 Jul 2010 11:28:13 +0000 (13:28 +0200)
* The default watchdog strategy on Win32 doesn't work because the watchdog
is executed via subshell ("cmd /c perl -e '...'"). When the test finishes
and tries to kill the watchdog all it manages to do is whack cmd.exe and
the watchdog still fires, potentially killing an innocent process.

* Trying to use the fork() strategy instead causes openpid.t's test #9's
"ok" to be lost occasionally.  The message itself is generated by the 4th
child of the test and should go directly to stdout, but sometimes the
output vanishes for unexplained reasons.  This doesn't appear to happen
without the watchdog enabled.

* Using the alarm() watchdog strategy seems to not cause any badness.

t/io/openpid.t [changed mode: 0644->0755]
t/test.pl [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index ee4702c..0e814d5
@@ -18,7 +18,7 @@ if ($^O eq 'dos') {
 }
 
 plan tests => 10;
-watchdog(15);
+watchdog(15, "alarm");
 
 use Config;
 $| = 1;
old mode 100644 (file)
new mode 100755 (executable)
index 6109d8e..c43c275
--- a/t/test.pl
+++ b/t/test.pl
@@ -809,9 +809,10 @@ WHOA
 # Set a watchdog to timeout the entire test file
 # NOTE:  If the test file uses 'threads', then call the watchdog() function
 #        _AFTER_ the 'threads' module is loaded.
-sub watchdog ($)
+sub watchdog ($;$)
 {
     my $timeout = shift;
+    my $method  = shift;
     my $timeout_msg = 'Test process timed out - terminating';
 
     # Valgrind slows perl way down so give it more time before dying.
@@ -819,6 +820,10 @@ sub watchdog ($)
 
     my $pid_to_kill = $$;   # PID for this process
 
+    if ($method eq "alarm") {
+        goto WATCHDOG_VIA_ALARM;
+    }
+
     # Don't use a watchdog process if 'threads' is loaded -
     #   use a watchdog thread instead
     if (! $threads::threads) {
@@ -925,6 +930,7 @@ sub watchdog ($)
     }
 
     # If everything above fails, then just use an alarm timeout
+WATCHDOG_VIA_ALARM:
     if (eval { alarm($timeout); 1; }) {
         # Load POSIX if available
         eval { require POSIX; };