Mercurial > hg > nginx-tests
diff limit_conn.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 | 1b205a3332de |
children | 684278f71783 |
line wrap: on
line diff
--- a/limit_conn.t Fri Jul 18 13:13:46 2014 +0400 +++ b/limit_conn.t Fri Jul 18 13:19:55 2014 +0400 @@ -104,7 +104,7 @@ # same and other zones in different locations -my $s = http_start('/w'); +my $s = http_get('/w', start => 1); like(http_get('/'), qr/^HTTP\/1.. 503 /, 'rejected'); like(http_get('/1'), qr/^HTTP\/1.. 503 /, 'rejected different location'); unlike(http_get('/zone'), qr/^HTTP\/1.. 503 /, 'passed different zone'); @@ -114,7 +114,7 @@ # custom error code and log level -$s = http_start('/custom/w'); +$s = http_get('/custom/w', start => 1); like(http_get('/custom'), qr/^HTTP\/1.. 501 /, 'limit_conn_status'); like(`grep -F '[info]' ${\($t->testdir())}/error.log`, @@ -123,7 +123,7 @@ # limit_zone -$s = http_start('/legacy/w'); +$s = http_get('/legacy/w', start => 1); like(http_get('/legacy'), qr/^HTTP\/1.. 503 /, 'legacy rejected'); $s->close; @@ -131,36 +131,8 @@ # limited after unlimited -$s = http_start('/w'); +$s = http_get('/w', start => 1); like(http_get('/unlim'), qr/404 Not Found/, 'unlimited passed'); like(http_get('/'), qr/503 Service/, 'limited rejected'); ############################################################################### - -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; -} - -###############################################################################