Explorar o código

Dpkg::IPC: add sanity check for timeout parameter and a non-regression test

Raphael Hertzog %!s(int64=17) %!d(string=hai) anos
pai
achega
f1d3f2dae6
Modificáronse 2 ficheiros con 15 adicións e 2 borrados
  1. 5 0
      scripts/Dpkg/IPC.pm
  2. 10 2
      scripts/t/800_Dpkg_IPC.t

+ 5 - 0
scripts/Dpkg/IPC.pm

@@ -157,6 +157,11 @@ sub _sanity_check_opts {
 	}
     }
 
+    if (exists $opts{"timeout"} and defined($opts{"timeout"}) and
+        $opts{"timeout"} !~ /^\d+$/) {
+	internerr("parameter timeout must be an integer");
+    }
+
     if (exists $opts{"env"} and ref($opts{"env"}) ne 'HASH') {
 	internerr("parameter env must be a hash reference");
     }

+ 10 - 2
scripts/t/800_Dpkg_IPC.t

@@ -1,6 +1,6 @@
 # -*- mode: cperl -*-
 
-use Test::More tests => 7;
+use Test::More tests => 8;
 
 use strict;
 use warnings;
@@ -45,7 +45,8 @@ is($string2, $string, "{from,to}_handle");
 $pid = fork_and_exec(exec => "cat",
 		     from_file => $tmp_name,
 		     to_file => $tmp2_name,
-		     wait_child => 1);
+		     wait_child => 1,
+		     timeout => 5);
 
 ok($pid);
 
@@ -55,5 +56,12 @@ close TMP;
 
 is($string2, $string, "{from,to}_file");
 
+eval {
+    $pid = fork_and_exec(exec => ["sleep", "10"],
+		         wait_child => 1,
+		         timeout => 5);
+};
+ok($@, "fails on timeout");
+
 unlink($tmp_name);
 unlink($tmp2_name);