summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Nierlein <Sven.Nierlein@consol.de>2014-06-12 11:56:48 (GMT)
committerSven Nierlein <Sven.Nierlein@consol.de>2014-06-12 11:56:48 (GMT)
commitc5a6c5136a2a7e629907b04a63dff059603bdb09 (patch)
treee6c9d47b240904752f2bf056bdc9dd92f7a83562
parent3529d7465d31234ec634939ed1a6bdc915b73ccd (diff)
downloadmonitoring-plugins-c5a6c5136a2a7e629907b04a63dff059603bdb09.tar.gz
tests: testCmd has own timeout which overwrites local one
so add configurable/optional timeout to testCmd. Signed-off-by: Sven Nierlein <Sven.Nierlein@consol.de>
-rw-r--r--NPTest.pm5
-rwxr-xr-xplugins/tests/check_http.t24
2 files changed, 12 insertions, 17 deletions
diff --git a/NPTest.pm b/NPTest.pm
index 2baed0b..e04ebba 100644
--- a/NPTest.pm
+++ b/NPTest.pm
@@ -627,12 +627,13 @@ sub only_output {
627} 627}
628 628
629sub testCmd { 629sub testCmd {
630 my $class = shift; 630 my $class = shift;
631 my $command = shift or die "No command passed to testCmd"; 631 my $command = shift or die "No command passed to testCmd";
632 my $timeout = shift || 120;
632 my $object = $class->new; 633 my $object = $class->new;
633 634
634 local $SIG{'ALRM'} = sub { die("timeout in command: $command"); }; 635 local $SIG{'ALRM'} = sub { die("timeout in command: $command"); };
635 alarm(120); # no test should take longer than 120 seconds 636 alarm($timeout); # no test should take longer than 120 seconds
636 637
637 my $output = `$command`; 638 my $output = `$command`;
638 $object->return_code($? >> 8); 639 $object->return_code($? >> 8);
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index 2c89beb..c40bb07 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -392,27 +392,21 @@ sub run_common_tests {
392 skip "This doesn't seems to work all the time", 1 unless ($ENV{HTTP_EXTERNAL}); 392 skip "This doesn't seems to work all the time", 1 unless ($ENV{HTTP_EXTERNAL});
393 $cmd = "$command -f follow -u /redir_external -t 5"; 393 $cmd = "$command -f follow -u /redir_external -t 5";
394 eval { 394 eval {
395 local $SIG{ALRM} = sub { die "alarm\n" }; 395 $result = NPTest->testCmd( $cmd, 2 );
396 alarm(2); 396 };
397 $result = NPTest->testCmd( $cmd ); 397 like( $@, "/timeout in command: $cmd/", $cmd );
398 alarm(0); };
399 is( $@, "alarm\n", $cmd );
400 } 398 }
401 399
402 $cmd = "$command -u /timeout -t 5"; 400 $cmd = "$command -u /timeout -t 5";
403 eval { 401 eval {
404 local $SIG{ALRM} = sub { die "alarm\n" }; 402 $result = NPTest->testCmd( $cmd, 2 );
405 alarm(2); 403 };
406 $result = NPTest->testCmd( $cmd ); 404 like( $@, "/timeout in command: $cmd/", $cmd );
407 alarm(0); };
408 is( $@, "alarm\n", $cmd );
409 405
410 $cmd = "$command -f follow -u /redir_timeout -t 2"; 406 $cmd = "$command -f follow -u /redir_timeout -t 2";
411 eval { 407 eval {
412 local $SIG{ALRM} = sub { die "alarm\n" }; 408 $result = NPTest->testCmd( $cmd, 5 );
413 alarm(5); 409 };
414 $result = NPTest->testCmd( $cmd ); 410 is( $@, "", $cmd );
415 alarm(0); };
416 isnt( $@, "alarm\n", $cmd );
417 411
418} 412}