Skip Menu |

This queue is for tickets about the Time-HiRes CPAN distribution.

Report information
The Basics
Id: 37340
Status: resolved
Priority: 0/
Queue: Time-HiRes

People
Owner: Nobody in particular
Requestors: jdhedden [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.9715
Fixed in: (no value)



Subject: [PATCH] Fix timer process in test
Under Cygwin, I frequently get failures from t/HiRes.t due to issues related to the handling of the timer process (i.e., the watchdog). I've attached a patch that I believe corrects those issues: 1. Uses SIGKILL instead of SIGTERM to help ensure the process is terminated. (No need to be subtle - the timer process has nothing to clean up.) 2. Call wait() to cleanup the timer process's status so that overlying test harnesses don't pick it up by mistake. (I believe this is one cause of some of the erroneous failures I've been encountering.) 3. Split the timer process's sleep() in two to work around bug #49073: http://rt.perl.org/rt3/Public/Bug/Display.html?id=49073
Subject: hires_t_patch.txt
--- Time-HiRes/t/HiRes.t +++ Time-HiRes/t/HiRes.t @@ -79,11 +79,14 @@ if ($timer_pid == 0) { # We are the kid, set up the timer. my $ppid = getppid(); print "# I am the timer process $$, sleeping for $waitfor seconds...\n"; - sleep($waitfor); - warn "\n$0: overall time allowed for tests (${waitfor}s) exceeded!\n"; - print "# Terminating main process $ppid...\n"; - kill('TERM', $ppid); - print "# This is the timer process $$, over and out.\n"; + sleep($waitfor - 2); # Workaround for perlbug #49073 + sleep(2); # Wait for parent to exit + if (kill(0, $ppid)) { # Check if parent still exists + warn "\n$0: overall time allowed for tests (${waitfor}s) exceeded!\n"; + print "# Terminating main process $ppid...\n"; + kill('KILL', $ppid); + print "# This is the timer process $$, over and out.\n"; + } exit(0); } else { print "# The timer process $timer_pid launched, continuing testing...\n"; @@ -733,8 +736,12 @@ if ($timer_pid) { # Only in the main process. my $left = $TheEnd - time(); printf "# I am the main process $$, terminating the timer process $timer_pid\n# before it terminates me in %d seconds (testing took %d seconds).\n", $left, $waitfor - $left; - my $kill = kill('TERM', $timer_pid); # We are done, the timer can go. - printf "# kill TERM $timer_pid = %d\n", $kill; + if (kill(0, $timer_pid)) { + local $?; + my $kill = kill('KILL', $timer_pid); # We are done, the timer can go. + wait(); + printf "# kill KILL $timer_pid = %d\n", $kill; + } unlink("ktrace.out"); # Used in BSD system call tracing. print "# All done.\n"; }
Subject: [PATCH-revised] Fix timer process in test
Show quoted text
> Under Cygwin, I frequently get failures from t/HiRes.t due > to issues related to the handling of the timer process > (i.e., the watchdog). I've attached a patch that I believe > corrects those issues: > > 1. Uses SIGKILL instead of SIGTERM to help ensure the > process is terminated. (No need to be subtle - the timer > process has nothing to clean up.) > > 2. Call wait() to cleanup the timer process's status so > that overlying test harnesses don't pick it up by mistake. > (I believe this is one cause of some of the erroneous > failures I've been encountering.) > > 3. Split the timer process's sleep() in two to work around > bug #49073: > http://rt.perl.org/rt3/Public/Bug/Display.html?id=49073
Revised patch assigns 0 to 'local $?' so it works properly.
# http://rt.cpan.org/Ticket/Display.html?id=37340 --- perl-current/ext/Time/HiRes/t/HiRes.t +++ perl-current/ext/Time/HiRes/t/HiRes.t @@ -79,11 +79,14 @@ if ($timer_pid == 0) { # We are the kid, set up the timer. my $ppid = getppid(); print "# I am the timer process $$, sleeping for $waitfor seconds...\n"; - sleep($waitfor); - warn "\n$0: overall time allowed for tests (${waitfor}s) exceeded!\n"; - print "# Terminating main process $ppid...\n"; - kill('TERM', $ppid); - print "# This is the timer process $$, over and out.\n"; + sleep($waitfor - 2); # Workaround for perlbug #49073 + sleep(2); # Wait for parent to exit + if (kill(0, $ppid)) { # Check if parent still exists + warn "\n$0: overall time allowed for tests (${waitfor}s) exceeded!\n"; + print "# Terminating main process $ppid...\n"; + kill('KILL', $ppid); + print "# This is the timer process $$, over and out.\n"; + } exit(0); } else { print "# The timer process $timer_pid launched, continuing testing...\n"; @@ -733,8 +736,12 @@ if ($timer_pid) { # Only in the main process. my $left = $TheEnd - time(); printf "# I am the main process $$, terminating the timer process $timer_pid\n# before it terminates me in %d seconds (testing took %d seconds).\n", $left, $waitfor - $left; - my $kill = kill('TERM', $timer_pid); # We are done, the timer can go. - printf "# kill TERM $timer_pid = %d\n", $kill; + if (kill(0, $timer_pid)) { + local $? = 0; + my $kill = kill('KILL', $timer_pid); # We are done, the timer can go. + wait(); + printf "# kill KILL $timer_pid = %d\n", $kill; + } unlink("ktrace.out"); # Used in BSD system call tracing. print "# All done.\n"; }
Please try 1.9716 or later.