Mercurial > hg > nginx-tests
diff proxy_cache_lock.t @ 438:60888e2c3f5a
Tests: new http_start() and http_end() functions.
When used together, they allow to break an http request into two separate
send/receive phases and are used to run long requests asynchronously.
An http() "start" extra flag introduced as a convenience shortcut.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 18 Jul 2014 13:19:55 +0400 |
parents | 847ea345becb |
children | 13ffba66f4e3 |
line wrap: on
line diff
--- a/proxy_cache_lock.t +++ b/proxy_cache_lock.t @@ -15,7 +15,7 @@ use Socket qw/ CRLF /; BEGIN { use FindBin; chdir($FindBin::Bin); } use lib 'lib'; -use Test::Nginx; +use Test::Nginx qw/ :DEFAULT http_end /; ############################################################################### @@ -87,7 +87,7 @@ for my $i (1 .. 5) { my @sockets; for my $i (1 .. 5) { - $sockets[$i] = http_start('/par1'); + $sockets[$i] = http_get('/par1', start => 1); } for my $i (1 .. 5) { @@ -99,7 +99,7 @@ like(http_get('/par1'), qr/request 1/, ' # parallel requests with cache lock timeout for my $i (1 .. 3) { - $sockets[$i] = http_start('/timeout'); + $sockets[$i] = http_get('/timeout', start => 1); } for my $i (1 .. 3) { @@ -111,7 +111,7 @@ like(http_get('/timeout'), qr/request 3/ # no lock for my $i (1 .. 3) { - $sockets[$i] = http_start('/nolock'); + $sockets[$i] = http_get('/nolock', start => 1); } for my $i (1 .. 3) { @@ -122,53 +122,6 @@ like(http_get('/nolock'), qr/request 3/, ############################################################################### -sub http_start { - my ($uri) = @_; - - my $s; - my $request = "GET $uri HTTP/1.0" . CRLF . CRLF; - - eval { - local $SIG{ALRM} = sub { die "timeout\n" }; - local $SIG{PIPE} = sub { die "sigpipe\n" }; - alarm(3); - $s = IO::Socket::INET->new( - Proto => 'tcp', - PeerAddr => '127.0.0.1:8080' - ); - log_out($request); - $s->print($request); - alarm(0); - }; - alarm(0); - if ($@) { - log_in("died: $@"); - return undef; - } - return $s; -} - -sub http_end { - my ($s) = @_; - my $reply; - - eval { - local $SIG{ALRM} = sub { die "timeout\n" }; - local $SIG{PIPE} = sub { die "sigpipe\n" }; - alarm(3); - local $/; - $reply = $s->getline(); - log_in($reply); - alarm(0); - }; - alarm(0); - if ($@) { - log_in("died: $@"); - return undef; - } - return $reply; -} - ############################################################################### sub http_fake_daemon {