Mercurial > hg > nginx-tests
annotate limit_conn.t @ 313:9daf28f20766
Tests: added tests for limit_conn module.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 15 Jul 2013 13:06:42 +0400 |
parents | |
children | 68b94b83412b |
rev | line source |
---|---|
313
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 # limit_req based tests for nginx limit_conn module. |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 ############################################################################### |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 use warnings; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use strict; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 use Test::More; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 use Socket qw/ CRLF /; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use lib 'lib'; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/http proxy limit_conn limit_req/)->plan(10); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 $t->write_file_expand('nginx.conf', <<'EOF'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 daemon off; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 events { |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 } |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 http { |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 %%TEST_GLOBALS_HTTP%% |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 limit_req_zone $binary_remote_addr zone=req:1m rate=1r/m; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 limit_conn_zone $binary_remote_addr zone=zone:1m; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 limit_conn_zone $binary_remote_addr zone=zone2:1m; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 limit_conn_zone $binary_remote_addr zone=custom:1m; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 limit_zone legacy $binary_remote_addr 1m; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 server { |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 listen 127.0.0.1:8081; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server_name localhost; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 location /w { |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 limit_req zone=req burst=10; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 } |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 } |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 server { |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 listen 127.0.0.1:8080; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 server_name localhost; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 location / { |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 proxy_pass http://127.0.0.1:8081; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 limit_conn zone 1; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 location /1 { |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 limit_conn zone 1; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 location /zone { |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 limit_conn zone2 1; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 } |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 location /unlim { |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 limit_conn zone 5; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 } |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 location /custom { |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 proxy_pass http://127.0.0.1:8081/; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 limit_conn_log_level info; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 limit_conn_status 501; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 limit_conn custom 1; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 } |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 location /legacy { |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 proxy_pass http://127.0.0.1:8081/; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 limit_conn legacy 1; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 } |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 } |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 } |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 EOF |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 $t->run(); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 ############################################################################### |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 # charge limit_req |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 http_get('/w'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 # same and other zones in different locations |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 my $s = http_start('/w'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 like(http_get('/'), qr/^HTTP\/1.. 503 /, 'rejected'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 like(http_get('/1'), qr/^HTTP\/1.. 503 /, 'rejected different location'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 unlike(http_get('/zone'), qr/^HTTP\/1.. 503 /, 'passed different zone'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 close $s; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 unlike(http_get('/1'), qr/^HTTP\/1.. 503 /, 'passed'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 # custom error code and log level |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 $s = http_start('/custom/w'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 like(http_get('/custom'), qr/^HTTP\/1.. 501 /, 'limit_conn_status'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 like(`grep -F '[info]' ${\($t->testdir())}/error.log`, |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 qr/limiting connections by zone "custom"/s, |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 'limit_conn_log_level'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 # limit_zone |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 $s = http_start('/legacy/w'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 like(http_get('/legacy'), qr/^HTTP\/1.. 503 /, 'legacy rejected'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 $s->close; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 unlike(http_get('/legacy'), qr/^HTTP\/.. 503 /, 'legacy passed'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 # limited after unlimited |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 $s = http_start('/w'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 like(http_get('/unlim'), qr/404 Not Found/, 'unlimited passed'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 like(http_get('/'), qr/503 Service/, 'limited rejected'); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 ############################################################################### |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 sub http_start { |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 my ($uri) = @_; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 my $s; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 my $request = "GET $uri HTTP/1.0" . CRLF . CRLF; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 eval { |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 local $SIG{ALRM} = sub { die "timeout\n" }; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 local $SIG{PIPE} = sub { die "sigpipe\n" }; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 alarm(3); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 $s = IO::Socket::INET->new( |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 Proto => 'tcp', |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 PeerAddr => '127.0.0.1:8080' |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 ); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 log_out($request); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 $s->print($request); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 alarm(0); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 }; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 alarm(0); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 if ($@) { |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 log_in("died: $@"); |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 return undef; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 } |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 return $s; |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 } |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 |
9daf28f20766
Tests: added tests for limit_conn module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 ############################################################################### |