$req->content($content);
}
$client->send_request($req, 4);
+ return $req;
+}
+
+=head2 wait
+
+Wait for a response to a previously sent request.
+
+=cut
+
+sub wait($) {
+ my ($self) = @_;
+
my ($ev, $resp) =
$self->run_loop('ev_server_timeout',
'ev_client_timeout',
if $ev eq 'ev_client_timeout';
die "Internal error\n"
unless $resp && ref($resp) && $resp->isa('HTTP::Response');
- $resp->request($req);
return $self->{'cached_response'} = $resp;
}
my $client = $self->new_client();
my $uri = __PACKAGE__ . "::$n";
- my $response = $self->get($client, $uri);
+ my $request = $self->get($client, $uri);
+ my $response = $self->wait();
$self->assert_body(qr/^(?:\Q$uri\E){$repeat}$/);
$client->shutdown();
return $response;
my $client = $self->new_client;
$self->post($client, "/pipe_me", [], $MAGIC_WORDS);
+ $self->wait();
$self->assert_ok();
$self->assert_no_xid();
$self->assert_body(qr/\Q$MAGIC_WORDS\E/);
# Warm up the cache
$self->post($client, "/cache_me");
+ $self->wait();
$self->assert_ok();
$self->assert_uncached();
$self->assert_body(qr/\Q$NOTHING_HAPPENS\E/);
# Verify that the request was cached
$self->post($client, "/cache_me");
+ $self->wait();
$self->assert_ok();
$self->assert_cached();
$self->assert_body(qr/\Q$NOTHING_HAPPENS\E/);
# Warm up the cache
$self->get($client, $KEEP_URL);
+ $self->wait();
$self->assert_ok();
$self->get($client, $PURGE_URL);
+ $self->wait();
$self->assert_ok();
# Verify the state of the cache
$self->get($client, $KEEP_URL);
+ $self->wait();
$self->assert_ok();
$self->assert_cached();
$self->get($client, $PURGE_URL);
+ $self->wait();
$self->assert_ok();
$self->assert_cached();
# Send the purge request
$self->request($client, 'REPURGE', $PURGE_RE);
+ $self->wait();
# Verify the state of the cache
$self->get($client, $KEEP_URL);
+ $self->wait();
$self->assert_ok();
$self->assert_cached();
$self->get($client, $PURGE_URL);
+ $self->wait();
$self->assert_ok();
$self->assert_uncached();
my $client = $self->new_client;
$self->get($client, '/');
+ $self->wait();
$self->assert_body($BODY);
$self->assert_uncached();
$self->post($client, '/');
+ $self->wait();
$self->assert_body($BODY);
$self->assert_cached();
$self->head($client, '/');
+ $self->wait();
$self->assert_no_body();
$self->assert_cached();
my $client = $self->new_client;
$self->get($client, '/');
+ $self->wait();
$self->assert_code($CODE);
$self->assert_body(qr/\Q$MESSAGE\E/);
$client->shutdown();
foreach my $lang (keys %languages) {
$self->get($client, '/', [ 'Accept-Language', $lang]);
+ $self->wait();
# $self->assert_uncached();
$self->assert_header('Language', $lang);
$self->assert_body($languages{$lang});
}
foreach my $lang (keys %languages) {
$self->get($client, '/', [ 'Accept-Language', $lang]);
+ $self->wait();
$self->assert_cached();
$self->assert_body($languages{$lang});
}
$self->{'responses'} += 1;
$self->logf("%s %s", $response->code(), $response->message());
- $self->{'engine'}->ev_client_response($self, $response, shift(@{$self->{'pending'}}));
+
+ # Associate the response with what we hope is the correct request
+ my $request = shift(@{$self->{'pending'}})
+ or die "received response while no request pending\n";
+ $response->request($request);
+
+ $self->{'engine'}->ev_client_response($self, $response);
}
=head2 shutdown