+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.
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;
}
print STDERR "Closing connection\n" if $log;
$con->close;
- undef($con);
}
}
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;
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");
: 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}) {
}
}
+
+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
},
);
-my $cmdline = "../src/wget http://localhost:8080/dummy.html";
+my $cmdline = "wget http://localhost:8080/dummy.html";
my $expected_error_code = 0;
},
);
-my $cmdline = "../src/wget -N http://localhost:8080/dummy.html";
+my $cmdline = "wget -N http://localhost:8080/dummy.html";
my $expected_error_code = 0;
},
);
-my $cmdline = "../src/wget --quiet http://localhost:8080/nonexistent";
+my $cmdline = "wget --quiet http://localhost:8080/nonexistent";
my $expected_error_code = 256;
},
);
-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;
},
);
-my $cmdline = "../src/wget http://localhost:8080/dummy.html";
+my $cmdline = "wget http://localhost:8080/dummy.html";
my $expected_error_code = 0;
},
);
-my $cmdline = "../src/wget http://localhost:8080/dummy.html";
+my $cmdline = "wget http://localhost:8080/dummy.html";
my $expected_error_code = 0;
},
);
-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;
--- /dev/null
+#!/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
+