[test suite] add synchronization between client and server processes
Mauro Tortonesi <[email protected]> Mon, 29 May 2006 11:15:22 +0200
| Newsgroups | gmane.comp.web.wget.patches |
|---|---|
| Message-ID | <[email protected]> |
This patch implements synchronization between client and server processes in the test suite to prevent the tests to start before the server is ready. In addition, it adds testing of recursive spider mode. 2006-05-26 Mauro Tortonesi <[email protected]> * 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. Index: tests/HTTPServer.pm =================================================================== --- tests/HTTPServer.pm (revisione 2148) +++ tests/HTTPServer.pm (copia locale) @@ -16,9 +16,16 @@ my $log = undef; sub run { - my ($self, $urls) = @_; + my ($self, $urls, $synch_callback) = @_; + my $initialized = 0; - while (my $con = $self->accept) { + while (1) { + if (!$initialized) { + $synch_callback->(); + $initialized = 1; + } + + 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 @@ } print STDERR "Closing connection\n" if $log; $con->close; - undef($con); } } Index: tests/Test1.px =================================================================== --- tests/Test1.px (revisione 2139) +++ tests/Test1.px (copia locale) @@ -23,7 +23,7 @@ }, ); -my $cmdline = "../src/wget http://localhost:8080/dummy.html"; +my $cmdline = "wget http://localhost:8080/dummy.html"; my $expected_error_code = 0; Index: tests/Test2.px =================================================================== --- tests/Test2.px (revisione 2139) +++ tests/Test2.px (copia locale) @@ -24,7 +24,7 @@ }, ); -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: tests/Test3.px =================================================================== --- tests/Test3.px (revisione 2139) +++ tests/Test3.px (copia locale) @@ -23,7 +23,7 @@ }, ); -my $cmdline = "../src/wget --quiet http://localhost:8080/nonexistent"; +my $cmdline = "wget --quiet http://localhost:8080/nonexistent"; my $expected_error_code = 256; Index: tests/Test4.px =================================================================== --- tests/Test4.px (revisione 2139) +++ tests/Test4.px (copia locale) @@ -23,7 +23,7 @@ }, ); -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: tests/HTTPTest.pm =================================================================== --- tests/HTTPTest.pm (revisione 2139) +++ tests/HTTPTest.pm (copia locale) @@ -35,11 +35,12 @@ 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: tests/Test.pm =================================================================== --- tests/Test.pm (revisione 2148) +++ tests/Test.pm (copia locale) @@ -72,11 +72,7 @@ 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 @@ : 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 _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: tests/Test5.px =================================================================== --- tests/Test5.px (revisione 2143) +++ tests/Test5.px (copia locale) @@ -33,7 +33,7 @@ }, ); -my $cmdline = "../src/wget http://localhost:8080/dummy.html"; +my $cmdline = "wget http://localhost:8080/dummy.html"; my $expected_error_code = 0; Index: tests/Test6.px =================================================================== --- tests/Test6.px (revisione 2143) +++ tests/Test6.px (copia locale) @@ -37,7 +37,7 @@ }, ); -my $cmdline = "../src/wget http://localhost:8080/dummy.html"; +my $cmdline = "wget http://localhost:8080/dummy.html"; my $expected_error_code = 0; Index: tests/Test7.px =================================================================== --- tests/Test7.px (revisione 2143) +++ tests/Test7.px (copia locale) @@ -37,7 +37,7 @@ }, ); -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; Index: tests/Test8.px =================================================================== --- tests/Test8.px (revisione 0) +++ tests/Test8.px (revisione 0) @@ -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 + -- Aequam memento rebus in arduis servare mentem... Mauro Tortonesi http://www.tortonesi.com University of Ferrara - Dept. of Eng. http://www.ing.unife.it GNU Wget - HTTP/FTP file retrieval tool http://www.gnu.org/software/wget Deep Space 6 - IPv6 for Linux http://www.deepspace6.net Ferrara Linux User Group http://www.ferrara.linux.it