[nagiosplug] tests: make sure tests don't hang

"Nagios Plugin Development" <[email protected]> Thu, 12 Sep 2013 21:40:09 +0000
Newsgroups gmane.network.nagios.plugins.cvs
Message-ID <[email protected]>
    Module: nagiosplug
    Branch: master
    Commit: 07f9a0f6274331ab6e45ac36ac1fe60d120dd2fb
    Author: Sven Nierlein <[email protected]>
 Committer: Sven Nierlein <[email protected]>
      Date: Thu Sep 12 13:55:36 2013 +0200
       URL: http://nagiosplug.git.sf.net/git/gitweb.cgi?p=nagiosplug/nagiosplug;a=commit;h=07f9a0f

tests: make sure tests don't hang

---

 NPTest.pm |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/NPTest.pm b/NPTest.pm
index 54a535e..a2cad19 100644
--- a/NPTest.pm
+++ b/NPTest.pm
@@ -615,7 +615,10 @@ sub testCmd {
 	my $class = shift;
 	my $command = shift or die "No command passed to testCmd";
 	my $object = $class->new;
-	
+
+	local $SIG{'ALRM'} = sub { die("timeout in command: $command"); };
+	alarm(120); # no test should take longer than 120 seconds
+
 	my $output = `$command`;
 	$object->return_code($? >> 8);
 	$_ = $? & 127;
@@ -625,6 +628,8 @@ sub testCmd {
 	chomp $output;
 	$object->output($output);
 
+	alarm(0);
+
 	my ($pkg, $file, $line) = caller(0);
 	print "Testing: $command", $/;
 	if ($ENV{'NPTEST_DEBUG'}) {


------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. Consolidate legacy IT systems to a single system of record for IT
2. Standardize and globalize service processes across IT
3. Implement zero-touch automation to replace manual, redundant tasks
http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk