Mercurial > hg > nginx-tests
comparison proxy_next_upstream.t @ 288:56157712d744
Tests: proxy_next_upstream tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 27 May 2013 16:51:59 +0400 |
parents | |
children | 3d3c8b5ea8ee |
comparison
equal
deleted
inserted
replaced
287:ba5b92378653 | 288:56157712d744 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for http proxy module, proxy_next_upstream directive. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(6); | |
25 | |
26 $t->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
28 %%TEST_GLOBALS%% | |
29 | |
30 daemon off; | |
31 | |
32 events { | |
33 } | |
34 | |
35 http { | |
36 %%TEST_GLOBALS_HTTP%% | |
37 | |
38 upstream u { | |
39 server 127.0.0.1:8081; | |
40 server 127.0.0.1:8082; | |
41 } | |
42 | |
43 server { | |
44 listen 127.0.0.1:8080; | |
45 server_name localhost; | |
46 | |
47 location / { | |
48 proxy_pass http://u; | |
49 proxy_next_upstream http_500 http_404; | |
50 } | |
51 } | |
52 | |
53 server { | |
54 listen 127.0.0.1:8081; | |
55 server_name localhost; | |
56 | |
57 location / { | |
58 return 404; | |
59 } | |
60 location /ok { | |
61 return 200 "AND-THIS\n"; | |
62 } | |
63 location /500 { | |
64 return 500; | |
65 } | |
66 } | |
67 | |
68 server { | |
69 listen 127.0.0.1:8082; | |
70 server_name localhost; | |
71 | |
72 location / { | |
73 return 200 "TEST-OK-IF-YOU-SEE-THIS\n"; | |
74 } | |
75 } | |
76 } | |
77 | |
78 EOF | |
79 | |
80 $t->run(); | |
81 | |
82 ############################################################################### | |
83 | |
84 # check if both request fallback to a backend | |
85 # which returns valid response | |
86 | |
87 like(http_get('/'), qr/SEE-THIS/, 'proxy request'); | |
88 like(http_get('/'), qr/SEE-THIS/, 'second request'); | |
89 | |
90 # make sure backend isn't switched off after | |
91 # proxy_next_upstream http_404 | |
92 | |
93 like(http_get('/ok') . http_get('/ok'), qr/AND-THIS/, 'not down'); | |
94 | |
95 # next upstream on http_500 | |
96 | |
97 like(http_get('/500'), qr/SEE-THIS/, 'request 500'); | |
98 like(http_get('/500'), qr/SEE-THIS/, 'request 500 second'); | |
99 | |
100 # make sure backend switched off with http_500 | |
101 | |
102 unlike(http_get('/ok') . http_get('/ok'), qr/AND-THIS/, 'down after 500'); | |
103 | |
104 ############################################################################### |