]> err.no Git - varnish/commitdiff
Separate the act of sending a request from that of receiving a response.
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 18 Oct 2007 15:45:34 +0000 (15:45 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 18 Oct 2007 15:45:34 +0000 (15:45 +0000)
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
varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm
varnish-tools/regress/lib/Varnish/Test/Case/POST.pm
varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm
varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm
varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm
varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm
varnish-tools/regress/lib/Varnish/Test/Client.pm

index b628b06a57d51c365171242856cb1ce0afcb5fe7..11f1b8a5843c8775478b8ec34216caf93403708f 100644 (file)
@@ -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;
 }
 
index 6491a081dde57a6da8547ee7a5c08adb8c68a65e..50275ad067bdacf00110ce65c0e11ae034dbb42d 100644 (file)
@@ -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;
index d413834e913b9afbaa987c867b242d89bbc3ffa0..90cb28e2e19da9800bbf74693704de0c7fe9d6ff 100644 (file)
@@ -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/);
index 1a262ebf1c745be811ad744b7c1a3a5450452517..e40b4a2dc2434cd0a85788530e88e4ff331c0c9c 100644 (file)
@@ -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();
 
index 03851f1770f9323b45590cb019b425bff30d5f9d..f40cb6126b8e3bbe587e44dea771fd57dca7b315 100644 (file)
@@ -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();
 
index 54dd3be2943c45998eb6120369699dfc9b7cf4d7..b6b1cb1fc1cbb929bfe76823a0964acfd7aa7367 100644 (file)
@@ -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();
index d24fd110042521265d960b108ccc1df5f16282d4..d44662152a63f266e1ca04de66f905846ac358f8 100644 (file)
@@ -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});
     }
index 950f5e7b6f15fcc50549055b6f77e8f0e4c5bb79..5f00474c11f16455a9d7120935191a4a1ddc0e6c 100644 (file)
@@ -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