From f2613b6ddb8784e5abfddc4e3ef2ec7aa4cb32bd Mon Sep 17 00:00:00 2001 From: mtortonesi Date: Mon, 29 May 2006 02:15:06 -0700 Subject: [PATCH] [svn] Add synchronization between client and server processes and testing of recursive spider mode. --- tests/ChangeLog | 25 ++++++++++++++++ tests/HTTPServer.pm | 12 ++++++-- tests/HTTPTest.pm | 3 +- tests/Test.pm | 35 +++++++++++++++++++---- tests/Test1.px | 2 +- tests/Test2.px | 2 +- tests/Test3.px | 2 +- tests/Test4.px | 2 +- tests/Test5.px | 2 +- tests/Test6.px | 2 +- tests/Test7.px | 2 +- tests/Test8.px | 69 +++++++++++++++++++++++++++++++++++++++++++++ 12 files changed, 141 insertions(+), 17 deletions(-) create mode 100755 tests/Test8.px diff --git a/tests/ChangeLog b/tests/ChangeLog index ac4109a5..a8974571 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,28 @@ +2006-05-26 Mauro Tortonesi + + * 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 * HTTPServer.pm: Fixed bug when returning 404. Improved logging. diff --git a/tests/HTTPServer.pm b/tests/HTTPServer.pm index 6747359e..8950a22d 100755 --- a/tests/HTTPServer.pm +++ b/tests/HTTPServer.pm @@ -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); } } diff --git a/tests/HTTPTest.pm b/tests/HTTPTest.pm index 20e9442f..7274adc6 100755 --- a/tests/HTTPTest.pm +++ b/tests/HTTPTest.pm @@ -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; diff --git a/tests/Test.pm b/tests/Test.pm index d996e77d..058a7c50 100755 --- a/tests/Test.pm +++ b/tests/Test.pm @@ -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 = ); + close FROM_CHILD; + } + + return $pid; +} + 1; # vim: et ts=4 sw=4 diff --git a/tests/Test1.px b/tests/Test1.px index 40cdef55..2da6cdae 100755 --- a/tests/Test1.px +++ b/tests/Test1.px @@ -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; diff --git a/tests/Test2.px b/tests/Test2.px index bf39936e..694769f8 100755 --- a/tests/Test2.px +++ b/tests/Test2.px @@ -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; diff --git a/tests/Test3.px b/tests/Test3.px index c8869b3f..d10f8ea9 100755 --- a/tests/Test3.px +++ b/tests/Test3.px @@ -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; diff --git a/tests/Test4.px b/tests/Test4.px index 3c259b46..60a4fd83 100755 --- a/tests/Test4.px +++ b/tests/Test4.px @@ -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; diff --git a/tests/Test5.px b/tests/Test5.px index 622b6bdf..c9bc62fa 100755 --- a/tests/Test5.px +++ b/tests/Test5.px @@ -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; diff --git a/tests/Test6.px b/tests/Test6.px index 864d5800..3727ad16 100755 --- a/tests/Test6.px +++ b/tests/Test6.px @@ -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; diff --git a/tests/Test7.px b/tests/Test7.px index 8c9e87cc..8064f76b 100755 --- a/tests/Test7.px +++ b/tests/Test7.px @@ -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 index 00000000..15fda010 --- /dev/null +++ b/tests/Test8.px @@ -0,0 +1,69 @@ +#!/usr/bin/perl -w + +use strict; + +use HTTPTest; + + +############################################################################### + +my $mainpage = < + + Main Page Title + + + Secondary Page + + +EOF + +my $subpage = < + + Secondary Page Title + + + Broken Link + + +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 + -- 2.39.2