Skip to content

Instantly share code, notes, and snippets.

@hidekiy
Created November 28, 2010 16:16
Show Gist options
  • Save hidekiy/719061 to your computer and use it in GitHub Desktop.
Save hidekiy/719061 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use AnyEvent::Handle;
use Plack::Handler::Twiggy;
use Test::TCP;
test_tcp(
client => sub {
my $port = shift;
while (1) {
my $done = AE::cv;
warn "requesting...";
for (0..100) {
$done->begin;
my $handle = AnyEvent::Handle->new(
connect => ['localhost', $port],
on_connect => sub {
my ($handle, $host, $port) = @_;
my $size = 1_000_000;
$handle->push_write(<<_END_);
POST / HTTP/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: $size
_END_
$handle->push_write('x' x ($size - 10));
$handle->destroy;
$done->end;
},
);
$handle->on_error(sub {
$handle;
});
}
$done->recv;
warn "destoyed";
my $wait = AE::cv;
my $t = AE::timer 15, 0, $wait;
$wait->recv;
}
},
server => sub {
my $port = shift;
my $handler = Plack::Handler::Twiggy->new(port => $port);
$handler->run(sub {
return [200, [], ['ok']];
})
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment