]> sjero.net Git - wget/blobdiff - tests/Test.pm
[svn] Minor fixes to test suite.
[wget] / tests / Test.pm
index d996e77d7612bea3f6675a4b29e128dc77df10a1..f1934de4f3f5be51df1f6d3cf400c449161b4c21 100755 (executable)
@@ -21,16 +21,16 @@ my @unexpected_downloads = ();
         _output       => {},
     );
     
-       sub _default_for
-       {
-               my ($self, $attr) = @_;
-               $_attr_data{$attr};
-       }
-
-       sub _standard_keys 
-       {
-               keys %_attr_data;
-       }
+    sub _default_for
+    {
+        my ($self, $attr) = @_;
+        $_attr_data{$attr};
+    }
+
+    sub _standard_keys 
+    {
+        keys %_attr_data;
+    }
 }
 
 
@@ -72,11 +72,7 @@ sub run {
     chdir ("$self->{_workdir}/$self->{_name}/input");
     
     # Launch server
-    my $pid = fork();
-    if($pid == 0) {
-        $self->_launch_server();
-    }
-    # print STDERR "Spawned server with pid: $pid\n"; 
+    my $pid = $self->_fork_and_launch_server();
     
     # Call wget
     chdir ("$self->{_workdir}/$self->{_name}/output");
@@ -87,8 +83,10 @@ sub run {
             : system ("$self->{_workdir}/../src/$self->{_cmdline}");
 
     # Shutdown server
+    # if we didn't explicitely kill the server, we would have to call 
+    # waitpid ($pid, 0) here in order to wait for the child process to 
+    # terminate
     kill ('TERM', $pid);
-    # print "Killed server\n";
 
     # Verify download
     unless ($errcode == $self->{_errcode}) {
@@ -211,6 +209,31 @@ sub __dir_walk {
     }
 }
 
+
+sub _fork_and_launch_server 
+{
+    my $self = shift;
+
+    pipe(FROM_CHILD, TO_PARENT) or die "Cannot create pipe!";
+    select((select(TO_PARENT), $| = 1)[0]);
+
+    my $pid = fork();
+    if ($pid < 0) {
+        die "Cannot fork";
+    } elsif ($pid == 0) {
+        # child 
+        close FROM_CHILD;
+        $self->_launch_server(sub { print TO_PARENT "SYNC\n"; close TO_PARENT });
+    } else {
+        # father
+        close TO_PARENT;
+        chomp(my $line = <FROM_CHILD>);
+        close FROM_CHILD;
+    }
+
+    return $pid;
+}
+
 1;
 
 # vim: et ts=4 sw=4