Mercurial > hg > nginx-tests
comparison upstream_hash.t @ 1036:38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 19 Sep 2016 13:58:34 +0300 |
parents | 882267679006 |
children | 766bcbb632ee |
comparison
equal
deleted
inserted
replaced
1035:c0accd6fab6c | 1036:38ed3dda3279 |
---|---|
20 ############################################################################### | 20 ############################################################################### |
21 | 21 |
22 select STDERR; $| = 1; | 22 select STDERR; $| = 1; |
23 select STDOUT; $| = 1; | 23 select STDOUT; $| = 1; |
24 | 24 |
25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite upstream_hash/)->plan(11); | 25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite upstream_hash/)->plan(13); |
26 | 26 |
27 $t->write_file_expand('nginx.conf', <<'EOF'); | 27 $t->write_file_expand('nginx.conf', <<'EOF'); |
28 | 28 |
29 %%TEST_GLOBALS%% | 29 %%TEST_GLOBALS%% |
30 | 30 |
112 location /bad { | 112 location /bad { |
113 proxy_pass http://bad; | 113 proxy_pass http://bad; |
114 } | 114 } |
115 location /cbad { | 115 location /cbad { |
116 proxy_pass http://cbad; | 116 proxy_pass http://cbad; |
117 } | |
118 location /busy { | |
119 proxy_pass http://bad/busy; | |
120 add_header X-IP $upstream_addr always; | |
121 } | |
122 location /cbusy { | |
123 proxy_pass http://cbad/busy; | |
124 add_header X-IP $upstream_addr always; | |
117 } | 125 } |
118 location /pnu { | 126 location /pnu { |
119 proxy_pass http://u/; | 127 proxy_pass http://u/; |
120 proxy_next_upstream http_502; | 128 proxy_next_upstream http_502; |
121 } | 129 } |
137 if ($server_port = %%PORT_8083%%) { | 145 if ($server_port = %%PORT_8083%%) { |
138 return 502; | 146 return 502; |
139 } | 147 } |
140 return 204; | 148 return 204; |
141 } | 149 } |
150 | |
151 location /busy { | |
152 return 444; | |
153 } | |
142 } | 154 } |
143 | 155 |
144 server { | 156 server { |
145 listen 127.0.0.1:8084; | 157 listen 127.0.0.1:8084; |
146 server_name localhost; | 158 server_name localhost; |
181 @res = grep { $_ == $p1 } iter('/bad', 20); | 193 @res = grep { $_ == $p1 } iter('/bad', 20); |
182 is(@res, 20, 'all hashed peers - bad'); | 194 is(@res, 20, 'all hashed peers - bad'); |
183 | 195 |
184 @res = grep { $_ == $p1 } iter('/cbad', 20); | 196 @res = grep { $_ == $p1 } iter('/cbad', 20); |
185 is(@res, 20, 'all hashed peers - bad consistent'); | 197 is(@res, 20, 'all hashed peers - bad consistent'); |
198 | |
199 like(http_get('/busy'), qr/X-IP: 127.0.0.1:$p1, bad/, | |
200 'upstream name - busy'); | |
201 | |
202 TODO: { | |
203 local $TODO = 'not yet' unless $t->has_version('1.11.5'); | |
204 | |
205 like(http_get('/cbusy'), qr/X-IP: 127.0.0.1:$p1, cbad/, | |
206 'upstream name - busy consistent'); | |
207 | |
208 } | |
186 | 209 |
187 ############################################################################### | 210 ############################################################################### |
188 | 211 |
189 # Returns true if two arrays follow consistency, i.e., they may only differ | 212 # Returns true if two arrays follow consistency, i.e., they may only differ |
190 # by @args present in $p, but absent in $p2, for the same indices. | 213 # by @args present in $p, but absent in $p2, for the same indices. |