]> sjero.net Git - wget/commitdiff
[svn] Add synchronization between client and server processes and testing of recursiv...
authormtortonesi <devnull@localhost>
Mon, 29 May 2006 09:15:06 +0000 (02:15 -0700)
committermtortonesi <devnull@localhost>
Mon, 29 May 2006 09:15:06 +0000 (02:15 -0700)
12 files changed:
tests/ChangeLog
tests/HTTPServer.pm
tests/HTTPTest.pm
tests/Test.pm
tests/Test1.px
tests/Test2.px
tests/Test3.px
tests/Test4.px
tests/Test5.px
tests/Test6.px
tests/Test7.px
tests/Test8.px [new file with mode: 0755]

index ac4109a57f19a7f2fe22d94b1098a18d67e61bc7..a8974571b5ae30efe15ea2b685444da520c82fbc 100644 (file)
@@ -1,3 +1,28 @@
+2006-05-26  Mauro Tortonesi  <mauro@ferrara.linux.it>
+
+       * HTTPServer.pm: Added synchronization between client and server
+       processes to prevent the test to start before the server is ready.
+
+       * HTTPTest.pm: Ditto.
+
+       * Test.pm: Ditto.
+
+       * Test1.px: Removed unneeded ../src/ from command line.
+
+       * Test2.px: Ditto.
+       
+       * Test3.px: Ditto.
+       
+       * Test4.px: Ditto.
+
+       * Test5.px: Ditto.
+
+       * Test6.px: Ditto.
+
+       * Test7.px: Ditto.
+
+       * Test8.px: Added test for recursive spider mode.
+
 2006-05-26  Mauro Tortonesi  <mauro@ferrara.linux.it>
 
        * HTTPServer.pm: Fixed bug when returning 404. Improved logging. 
index 6747359ec648cde68f435f1946194a4bb0b434af..8950a22de2309d7cb37cfff7dd0863c9005e2873 100755 (executable)
@@ -16,9 +16,16 @@ my $CRLF = "\015\012"; # "\r\n" is not portable
 my $log = undef;
 
 sub run {
-    my ($self, $urls) = @_;
+    my ($self, $urls, $synch_callback) = @_;
+    my $initialized = 0;
+
+    while (1) {
+        if (!$initialized) {
+            $synch_callback->();
+            $initialized = 1;
+        }        
                                 
-    while (my $con = $self->accept) {
+        my $con = $self->accept();
         print STDERR "Accepted a new connection\n" if $log;
         while (my $req = $con->get_request) {
             my $url_path = $req->url->path;
@@ -77,7 +84,6 @@ sub run {
         }
         print STDERR "Closing connection\n" if $log;
         $con->close;
-        undef($con);
     }
 }
 
index 20e9442f01692bfff03e8a6a16f9ca41590360b9..7274adc6bea620fc531cea18efd5ffd2ecdd7257 100755 (executable)
@@ -35,11 +35,12 @@ sub _setup_server {}
 
 sub _launch_server {
     my $self = shift;
+    my $synch_func = shift;
 
     my $server = HTTPServer->new (LocalAddr => 'localhost',
                                   LocalPort => '8080',
                                   ReuseAddr => 1) or die "Cannot create server!!!";
-    $server->run ($self->{_input});
+    $server->run ($self->{_input}, $synch_func);
 }
 
 1;
index d996e77d7612bea3f6675a4b29e128dc77df10a1..058a7c505807dff05a65f936e46e2683e4f85b56 100755 (executable)
@@ -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
index 40cdef55ecab135260ecd19b33a6b1d900bbd125..2da6cdaeb9d71514306d99209e219b6d09527187 100755 (executable)
@@ -23,7 +23,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "../src/wget http://localhost:8080/dummy.html";
+my $cmdline = "wget http://localhost:8080/dummy.html";
 
 my $expected_error_code = 0;
 
index bf39936ed3861d0ba03b5bfc08cf8e4fedf615e3..694769f8536f558036c8f5f1712ad589ba2bf32c 100755 (executable)
@@ -24,7 +24,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "../src/wget -N http://localhost:8080/dummy.html";
+my $cmdline = "wget -N http://localhost:8080/dummy.html";
 
 my $expected_error_code = 0;
 
index c8869b3f1414748f57f6e8aeeb53167856fcea61..d10f8ea9cb7ae6847fb8134029c26ae46bf22887 100755 (executable)
@@ -23,7 +23,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "../src/wget --quiet http://localhost:8080/nonexistent";
+my $cmdline = "wget --quiet http://localhost:8080/nonexistent";
 
 my $expected_error_code = 256;
 
index 3c259b4692df6b0f3f0cd5f49941ce90fa7cfe0d..60a4fd83718d0e4e78267b800229239a0b746dff 100755 (executable)
@@ -23,7 +23,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "../src/wget --quiet -O out http://localhost:8080/nonexistent";
+my $cmdline = "wget --quiet -O out http://localhost:8080/nonexistent";
 
 my $expected_error_code = 11;
 
index 622b6bdf5745753ca397d933e5ed8de5dcd8eb72..c9bc62fa9d0d5d2b00c17e860260359205bd13ef 100755 (executable)
@@ -33,7 +33,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "../src/wget http://localhost:8080/dummy.html";
+my $cmdline = "wget http://localhost:8080/dummy.html";
 
 my $expected_error_code = 0;
 
index 864d5800319d50dfe3bfbaceec8bcb03d0070c81..3727ad162187647579d4a8492241830ccbefb1d1 100755 (executable)
@@ -37,7 +37,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "../src/wget http://localhost:8080/dummy.html";
+my $cmdline = "wget http://localhost:8080/dummy.html";
 
 my $expected_error_code = 0;
 
index 8c9e87ccc37224e226a48165aa006028226dabd1..8064f76bf2ef1da96d007bed66a49c29b5270fa3 100755 (executable)
@@ -37,7 +37,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "../src/wget --no-content-disposition http://localhost:8080/dummy.html";
+my $cmdline = "wget --no-content-disposition http://localhost:8080/dummy.html";
 
 my $expected_error_code = 0;
 
diff --git a/tests/Test8.px b/tests/Test8.px
new file mode 100755 (executable)
index 0000000..15fda01
--- /dev/null
@@ -0,0 +1,69 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use HTTPTest;
+
+
+###############################################################################
+
+my $mainpage = <<EOF;
+<html>
+<head>
+  <title>Main Page Title</title>
+</head>
+<body>
+  <a href="http://localhost:8080/subpage.html">Secondary Page</a>
+</body>
+</html>
+EOF
+
+my $subpage = <<EOF;
+<html>
+<head>
+  <title>Secondary Page Title</title>
+</head>
+<body>
+  <a href="http://localhost:8080/nonexistent">Broken Link</a>
+</body>
+</html>
+EOF
+
+# code, msg, headers, content
+my %urls = (
+    '/index.html' => {
+        code => "200",
+        msg => "Dontcare",
+        headers => {
+            "Content-type" => "text/html",
+        },
+        content => $mainpage,
+    },
+    '/subpage.html' => {
+        code => "200",
+        msg => "Dontcare",
+        headers => {
+            "Content-type" => "text/html",
+        },
+        content => $subpage,
+    },
+);
+
+my $cmdline = "wget -Sd --spider -r http://localhost:8080/";
+
+my $expected_error_code = 0;
+
+my %expected_downloaded_files = (
+);
+
+###############################################################################
+
+my $the_test = HTTPTest->new (name => "Test8",
+                              input => \%urls, 
+                              cmdline => $cmdline, 
+                              errcode => $expected_error_code, 
+                              output => \%expected_downloaded_files);
+$the_test->run();
+
+# vim: et ts=4 sw=4
+