Mercurial > hg > nginx-tests
comparison proxy_next_upstream.t @ 351:3d3c8b5ea8ee
Tests: improved proxy_next_upstream tests.
A new test added to make sure that all bad backends are tried once.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 24 Oct 2013 12:21:15 +0400 |
parents | 56157712d744 |
children | e9064d691790 |
comparison
equal
deleted
inserted
replaced
350:e102fc6db946 | 351:3d3c8b5ea8ee |
---|---|
19 ############################################################################### | 19 ############################################################################### |
20 | 20 |
21 select STDERR; $| = 1; | 21 select STDERR; $| = 1; |
22 select STDOUT; $| = 1; | 22 select STDOUT; $| = 1; |
23 | 23 |
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(6); | 24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(7); |
25 | 25 |
26 $t->write_file_expand('nginx.conf', <<'EOF'); | 26 $t->write_file_expand('nginx.conf', <<'EOF'); |
27 | 27 |
28 %%TEST_GLOBALS%% | 28 %%TEST_GLOBALS%% |
29 | 29 |
38 upstream u { | 38 upstream u { |
39 server 127.0.0.1:8081; | 39 server 127.0.0.1:8081; |
40 server 127.0.0.1:8082; | 40 server 127.0.0.1:8082; |
41 } | 41 } |
42 | 42 |
43 upstream u2 { | |
44 server 127.0.0.1:8081; | |
45 server 127.0.0.1:8082; | |
46 } | |
47 | |
43 server { | 48 server { |
44 listen 127.0.0.1:8080; | 49 listen 127.0.0.1:8080; |
45 server_name localhost; | 50 server_name localhost; |
46 | 51 |
47 location / { | 52 location / { |
48 proxy_pass http://u; | 53 proxy_pass http://u; |
49 proxy_next_upstream http_500 http_404; | 54 proxy_next_upstream http_500 http_404; |
55 } | |
56 | |
57 location /all/ { | |
58 proxy_pass http://u2; | |
59 proxy_next_upstream http_500 http_404; | |
60 error_page 404 /all/404; | |
61 proxy_intercept_errors on; | |
62 } | |
63 | |
64 location /all/404 { | |
65 return 200 "$upstream_addr\n"; | |
50 } | 66 } |
51 } | 67 } |
52 | 68 |
53 server { | 69 server { |
54 listen 127.0.0.1:8081; | 70 listen 127.0.0.1:8081; |
61 return 200 "AND-THIS\n"; | 77 return 200 "AND-THIS\n"; |
62 } | 78 } |
63 location /500 { | 79 location /500 { |
64 return 500; | 80 return 500; |
65 } | 81 } |
82 | |
83 location /all/ { | |
84 return 404; | |
85 } | |
66 } | 86 } |
67 | 87 |
68 server { | 88 server { |
69 listen 127.0.0.1:8082; | 89 listen 127.0.0.1:8082; |
70 server_name localhost; | 90 server_name localhost; |
71 | 91 |
72 location / { | 92 location / { |
73 return 200 "TEST-OK-IF-YOU-SEE-THIS\n"; | 93 return 200 "TEST-OK-IF-YOU-SEE-THIS\n"; |
94 } | |
95 | |
96 location /all/ { | |
97 return 404; | |
74 } | 98 } |
75 } | 99 } |
76 } | 100 } |
77 | 101 |
78 EOF | 102 EOF |
99 | 123 |
100 # make sure backend switched off with http_500 | 124 # make sure backend switched off with http_500 |
101 | 125 |
102 unlike(http_get('/ok') . http_get('/ok'), qr/AND-THIS/, 'down after 500'); | 126 unlike(http_get('/ok') . http_get('/ok'), qr/AND-THIS/, 'down after 500'); |
103 | 127 |
128 # make sure all backends are tried once | |
129 | |
130 like(http_get('/all/rr'), | |
131 qr/^127.0.0.1:808(1, 127.0.0.1:8082|2, 127.0.0.1:8081)$/mi, | |
132 'all tried once'); | |
133 | |
104 ############################################################################### | 134 ############################################################################### |