Mercurial > hg > nginx-tests
comparison proxy_non_idempotent.t @ 887:5debefd670bc
Tests: proxy_next_upstream non_idempotent tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 28 Mar 2016 19:47:38 +0300 |
parents | |
children | e9064d691790 |
comparison
equal
deleted
inserted
replaced
886:af2cd0ba6ca7 | 887:5debefd670bc |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for proxy_next_upstream non_idempotent. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite upstream_keepalive/); | |
26 | |
27 $t->write_file_expand('nginx.conf', <<'EOF'); | |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 upstream u { | |
40 server 127.0.0.1:8081 max_fails=0; | |
41 server 127.0.0.1:8081 max_fails=0; | |
42 } | |
43 | |
44 upstream uk { | |
45 server 127.0.0.1:8081 max_fails=0; | |
46 server 127.0.0.1:8081 max_fails=0; | |
47 keepalive 10; | |
48 } | |
49 | |
50 server { | |
51 listen 127.0.0.1:8080; | |
52 server_name localhost; | |
53 | |
54 add_header X-IP $upstream_addr always; | |
55 | |
56 location / { | |
57 proxy_pass http://u; | |
58 proxy_next_upstream error timeout; | |
59 } | |
60 | |
61 location /non { | |
62 proxy_pass http://u; | |
63 proxy_next_upstream error timeout non_idempotent; | |
64 } | |
65 | |
66 location /keepalive { | |
67 proxy_pass http://uk; | |
68 proxy_next_upstream error timeout; | |
69 proxy_http_version 1.1; | |
70 proxy_set_header Connection ""; | |
71 } | |
72 } | |
73 | |
74 server { | |
75 listen 127.0.0.1:8081; | |
76 server_name localhost; | |
77 | |
78 location / { | |
79 return 444; | |
80 } | |
81 | |
82 location /keepalive/establish { | |
83 return 204; | |
84 } | |
85 } | |
86 } | |
87 | |
88 EOF | |
89 | |
90 $t->try_run('no proxy_next_upstream non_idempotent')->plan(6); | |
91 | |
92 ############################################################################### | |
93 | |
94 # non-idempotent requests should not be retried by default | |
95 # if a request has been sent to a backend | |
96 | |
97 like(http_get('/'), qr/X-IP: (\S+), \1\x0d?$/m, 'get'); | |
98 like(http_post('/'), qr/X-IP: (\S+)\x0d?$/m, 'post'); | |
99 | |
100 # with "proxy_next_upstream non_idempotent" there is no | |
101 # difference between idempotent and non-idempotent requests, | |
102 # non-idempotent requests are retried as usual | |
103 | |
104 like(http_get('/non'), qr/X-IP: (\S+), \1\x0d?$/m, 'get non_idempotent'); | |
105 like(http_post('/non'), qr/X-IP: (\S+), \1\x0d?$/m, 'post non_idempotent'); | |
106 | |
107 # cached connections follow the same rules | |
108 | |
109 like(http_get('/keepalive/establish'), qr/204 No Content/m, 'keepalive'); | |
110 like(http_post('/keepalive/drop'), qr/X-IP: (\S+)\x0d?$/m, 'keepalive post'); | |
111 | |
112 ############################################################################### | |
113 | |
114 sub http_post { | |
115 my ($uri, %extra) = @_; | |
116 my $cl = $extra{cl} || 0; | |
117 | |
118 http(<<"EOF"); | |
119 POST $uri HTTP/1.0 | |
120 Content-Length: $cl | |
121 | |
122 EOF | |
123 } | |
124 | |
125 ############################################################################### |