BEGIN { push @INC, './t'; print STDERR "*** Note: This test may run for a minute or more\n"; print STDERR "*** Note2: several harmless \"Scalars leaked\" messages may be reported\n"; } use Test::More tests => 1; use threads; use LWP::Simple; use LWP::UserAgent; use LWPBulkFetch; use strict; use warnings; my $thrdcnt = 4; my $child1; my $sep = ($^O eq 'MSWin32') ? '\\' : '/'; my $forkhttpd = 1; # # NOTE: we need to use different port than 01basics.t, since some # platforms hang onto the listener port for extended periods # after we've closed it # my $port = 12876; my $result = 0; my $cycles = 20; my $quiet = 1; while (@ARGV) { my $opt = shift @ARGV; $thrdcnt = shift @ARGV, next if ($opt eq '-t'); $forkhttpd = undef, next if ($opt eq '-n'); $port = shift @ARGV, next if ($opt eq '-p'); $cycles = shift @ARGV, next if ($opt eq '-c'); $quiet = undef, next if ($opt eq '-l'); } if ($forkhttpd) { $child1 = fork(); die "Can't fork HTTP Client child: $!" unless defined $child1; unless ($child1) { my $cmd = 'perl -w t' . $sep . "cgidtest.pl -p $port -c 5 -d ./t -l 1 -s"; system($cmd); exit 1; } # # wait a while for things to get rolling # sleep 5; } # # start some threads # my @thrds = (); push @thrds, threads->create(\&run, $port, $cycles) foreach (1..$thrdcnt); # # wait for them to get rolling # sleep 5; # # wait for them to finish # $result += $_->join() foreach (@thrds); #print "Result is $result\n"; is($result, $thrdcnt, 'stress test'); # # shutdown the server # if ($forkhttpd) { get "http://localhost:$port/stop"; kill($child1); waitpid($child1, 0); } sub run { my ($port, $cycles) = @_; my $url = "http://localhost:$port/"; my $index = '
Some really simple HTML.'; my ($ct, $cl, $mtime, $exp, $server); my $indexlen = length($index); # change this! # # now run each LWP request and see what we get back # # 1. simple HEAD # foreach (1..$cycles) { print STDERR "Simple HEAD\n" unless $quiet; ($ct, $cl, $mtime, $exp, $server) = head($url . 'index.html'); return 0 unless (defined($ct) && ($ct eq 'text/html')); # # 2. simple GET # print STDERR "Simple GET\n" unless $quiet; my $page = get $url; return 0 unless (defined($page) && ($page eq $index)); # # 3. document HEAD # print STDERR "Document HEAD\n" unless $quiet; my $jspage = '/* this would normally be a nice piece of javascript */ '; ($ct, $cl, $mtime, $exp, $server) = head($url . 'scripty.js'); return 0 unless (defined($ct) && ($ct eq 'text/javascript') && defined($cl) && (($cl == crlen($jspage)) || ($cl == length($jspage)))); # # 4. CGI HEAD # print STDERR "CGI HEAD\n" unless $quiet; my $postpg = <<'EOPAGE';