From 6a7c8389e4ab06f25e6d04b56ff3a7650d69dbd3 Mon Sep 17 00:00:00 2001 From: des Date: Thu, 18 Oct 2007 15:45:34 +0000 Subject: [PATCH] Separate the act of sending a request from that of receiving a response. This (along with earlier changes to the client code) allows us to send multiple requests, then receive the responses in order. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2118 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-tools/regress/lib/Varnish/Test/Case.pm | 13 ++++++++++++- varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm | 3 ++- varnish-tools/regress/lib/Varnish/Test/Case/POST.pm | 3 +++ .../regress/lib/Varnish/Test/Case/RePurge.pm | 7 +++++++ .../regress/lib/Varnish/Test/Case/Ticket102.pm | 3 +++ .../regress/lib/Varnish/Test/Case/Ticket128.pm | 1 + varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm | 2 ++ varnish-tools/regress/lib/Varnish/Test/Client.pm | 8 +++++++- 8 files changed, 37 insertions(+), 3 deletions(-) diff --git a/varnish-tools/regress/lib/Varnish/Test/Case.pm b/varnish-tools/regress/lib/Varnish/Test/Case.pm index b628b06a..11f1b8a5 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case.pm @@ -346,6 +346,18 @@ sub request($$$$;$$) { $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', @@ -356,7 +368,6 @@ sub request($$$$;$$) { 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; } diff --git a/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm b/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm index 6491a081..50275ad0 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm @@ -51,7 +51,8 @@ sub _testLRU($$) { 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; diff --git a/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm b/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm index d413834e..90cb28e2 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm @@ -79,6 +79,7 @@ sub testPipePOST($) { 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/); @@ -93,12 +94,14 @@ sub testCachePOST($) { # 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/); diff --git a/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm b/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm index 1a262ebf..e40b4a2d 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm @@ -58,26 +58,33 @@ sub testPagePurged($) { # 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(); diff --git a/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm b/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm index 03851f17..f40cb612 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm @@ -53,14 +53,17 @@ sub testBodyInCachedPOST($) { 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(); diff --git a/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm b/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm index 54dd3be2..b6b1cb1f 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm @@ -49,6 +49,7 @@ sub testSyntheticError($) { my $client = $self->new_client; $self->get($client, '/'); + $self->wait(); $self->assert_code($CODE); $self->assert_body(qr/\Q$MESSAGE\E/); $client->shutdown(); diff --git a/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm b/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm index d24fd110..d4466215 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm @@ -49,12 +49,14 @@ sub testVary($) { 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}); } diff --git a/varnish-tools/regress/lib/Varnish/Test/Client.pm b/varnish-tools/regress/lib/Varnish/Test/Client.pm index 950f5e7b..5f00474c 100644 --- a/varnish-tools/regress/lib/Varnish/Test/Client.pm +++ b/varnish-tools/regress/lib/Varnish/Test/Client.pm @@ -133,7 +133,13 @@ sub got_response($$) { $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 -- 2.39.5