[svn] Add synchronization between client and server processes and testing of recursive spider mode.

This commit is contained in:
mtortonesi 2006-05-29 02:15:06 -07:00
parent a309257cbd
commit f2613b6ddb
12 changed files with 141 additions and 17 deletions

View 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.

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

69
tests/Test8.px Executable file
View File

@ -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