[omd-commits] OMD Git: omd: tests: added timeout for commands

git version control git at mathias-kettner.de
Sun Dec 19 00:11:35 CET 2010


Module: omd
Branch: master
Commit: 1c98a5b8c87cb9673d9d413b7d777391d92ff412
URL:    http://omdistro.org/projects/omd/repository/revisions/1c98a5b8c87cb9673d9d413b7d777391d92ff412

Author: Sven Nierlein <sven at nierlein.de>
Date:   Sun Dec 19 00:11:14 2010 +0100

tests: added timeout for commands

---

 t/TestUtils.pm |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/t/TestUtils.pm b/t/TestUtils.pm
index 19b0a51..7d18995 100644
--- a/t/TestUtils.pm
+++ b/t/TestUtils.pm
@@ -99,10 +99,22 @@ sub read_distro_config {
 =cut
 sub test_command {
     my $test = shift;
+    my( $rc, $stderr);
     my($prg,$arg) = split(/\s+/, $test->{'cmd'}, 2);
     my $t = Test::Cmd->new(prog => $prg, workdir => '') or die($!);
-    $t->run(args => $arg, stdin => $test->{'stdin'});
-    my $rc = $?>>8;
+    alarm(120);
+    eval {
+        local $SIG{ALRM} = sub { die "timeout on cmd: ".$test->{'cmd'}."\n" };
+        $t->run(args => $arg, stdin => $test->{'stdin'});
+        $rc = $?>>8;
+    };
+    if($@) {
+        $stderr = $@;
+    } else {
+        $stderr = $t->stderr;
+        $stderr = TestUtils::_clean_stderr($stderr);
+    }
+    alarm(0);
 
     # run the command
     isnt($rc, undef, "cmd: ".$test->{'cmd'});
@@ -124,7 +136,7 @@ sub test_command {
     $test->{'errlike'} = '/^$/' unless exists $test->{'errlike'};
     if(defined $test->{'errlike'}) {
         for my $expr (ref $test->{'errlike'} eq 'ARRAY' ? @{$test->{'errlike'}} : $test->{'errlike'} ) {
-            like($t->stderr, $expr, "stderr like ".$expr) || diag("\ncmd: '".$test->{'cmd'}."' failed");
+            like($stderr, $expr, "stderr like ".$expr) || diag("\ncmd: '".$test->{'cmd'}."' failed");
         }
     }
 
@@ -378,6 +390,20 @@ sub _get_url {
     return $newurl;
 }
 
+
+##################################################
+
+=head2 _clean_stderr
+
+  remove some know errors from stderr
+
+=cut
+sub _clean_stderr {
+    my $text = shift || '';
+    $text =~ s/httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName//;
+    return $text;
+}
+
 END {
     if(defined $omd_symlink_created and $omd_symlink_created == 1) {
         unlink('/omd');



More information about the omd-commits mailing list