Mercurial > hg > nginx-tests
comparison 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 |
comparison
equal
deleted
inserted
replaced
437:8b4a6b8691eb | 438:60888e2c3f5a |
---|---|
102 | 102 |
103 http_get('/w'); | 103 http_get('/w'); |
104 | 104 |
105 # same and other zones in different locations | 105 # same and other zones in different locations |
106 | 106 |
107 my $s = http_start('/w'); | 107 my $s = http_get('/w', start => 1); |
108 like(http_get('/'), qr/^HTTP\/1.. 503 /, 'rejected'); | 108 like(http_get('/'), qr/^HTTP\/1.. 503 /, 'rejected'); |
109 like(http_get('/1'), qr/^HTTP\/1.. 503 /, 'rejected different location'); | 109 like(http_get('/1'), qr/^HTTP\/1.. 503 /, 'rejected different location'); |
110 unlike(http_get('/zone'), qr/^HTTP\/1.. 503 /, 'passed different zone'); | 110 unlike(http_get('/zone'), qr/^HTTP\/1.. 503 /, 'passed different zone'); |
111 | 111 |
112 close $s; | 112 close $s; |
113 unlike(http_get('/1'), qr/^HTTP\/1.. 503 /, 'passed'); | 113 unlike(http_get('/1'), qr/^HTTP\/1.. 503 /, 'passed'); |
114 | 114 |
115 # custom error code and log level | 115 # custom error code and log level |
116 | 116 |
117 $s = http_start('/custom/w'); | 117 $s = http_get('/custom/w', start => 1); |
118 like(http_get('/custom'), qr/^HTTP\/1.. 501 /, 'limit_conn_status'); | 118 like(http_get('/custom'), qr/^HTTP\/1.. 501 /, 'limit_conn_status'); |
119 | 119 |
120 like(`grep -F '[info]' ${\($t->testdir())}/error.log`, | 120 like(`grep -F '[info]' ${\($t->testdir())}/error.log`, |
121 qr/limiting connections by zone "custom"/s, | 121 qr/limiting connections by zone "custom"/s, |
122 'limit_conn_log_level'); | 122 'limit_conn_log_level'); |
123 | 123 |
124 # limit_zone | 124 # limit_zone |
125 | 125 |
126 $s = http_start('/legacy/w'); | 126 $s = http_get('/legacy/w', start => 1); |
127 like(http_get('/legacy'), qr/^HTTP\/1.. 503 /, 'legacy rejected'); | 127 like(http_get('/legacy'), qr/^HTTP\/1.. 503 /, 'legacy rejected'); |
128 | 128 |
129 $s->close; | 129 $s->close; |
130 unlike(http_get('/legacy'), qr/^HTTP\/.. 503 /, 'legacy passed'); | 130 unlike(http_get('/legacy'), qr/^HTTP\/.. 503 /, 'legacy passed'); |
131 | 131 |
132 # limited after unlimited | 132 # limited after unlimited |
133 | 133 |
134 $s = http_start('/w'); | 134 $s = http_get('/w', start => 1); |
135 like(http_get('/unlim'), qr/404 Not Found/, 'unlimited passed'); | 135 like(http_get('/unlim'), qr/404 Not Found/, 'unlimited passed'); |
136 like(http_get('/'), qr/503 Service/, 'limited rejected'); | 136 like(http_get('/'), qr/503 Service/, 'limited rejected'); |
137 | 137 |
138 ############################################################################### | 138 ############################################################################### |
139 | |
140 sub http_start { | |
141 my ($uri) = @_; | |
142 | |
143 my $s; | |
144 my $request = "GET $uri HTTP/1.0" . CRLF . CRLF; | |
145 | |
146 eval { | |
147 local $SIG{ALRM} = sub { die "timeout\n" }; | |
148 local $SIG{PIPE} = sub { die "sigpipe\n" }; | |
149 alarm(3); | |
150 $s = IO::Socket::INET->new( | |
151 Proto => 'tcp', | |
152 PeerAddr => '127.0.0.1:8080' | |
153 ); | |
154 log_out($request); | |
155 $s->print($request); | |
156 alarm(0); | |
157 }; | |
158 alarm(0); | |
159 if ($@) { | |
160 log_in("died: $@"); | |
161 return undef; | |
162 } | |
163 return $s; | |
164 } | |
165 | |
166 ############################################################################### |