Mercurial > hg > nginx-tests
annotate upstream_hash.t @ 572:ca54b445d982
Tests: masked nginx bug in proxy next upstream.
When iterating through several next upstreams per a worker cycle,
a previously reported event about upstream connection error may
be improperly applied to the next upstream, thus leading to the
invalid connection error. E.g., in kqueue, where the problem is
visible, this is caused by "ev->instance" that does not tolerate
more than one next upstream at once, and kevents placed on the
kqueue separately for read and write events.
The change is to limit test case to the only one next upstream.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 14 May 2015 11:54:24 +0300 |
parents | 907e89fba9c3 |
children | 6cdfd177319b |
rev | line source |
---|---|
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for upstream hash balancer module. |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
568
907e89fba9c3
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
457
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite upstream_hash/)->plan(11); |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 upstream u { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 hash $arg_a; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server 127.0.0.1:8081; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 server 127.0.0.1:8082; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server 127.0.0.1:8083; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 upstream u2 { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 hash $arg_a; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 server 127.0.0.1:8081; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 server 127.0.0.1:8083; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 upstream cw { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 hash $arg_a consistent; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 server 127.0.0.1:8081; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 server 127.0.0.1:8082; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 server 127.0.0.1:8083 weight=10; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 upstream cw2 { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 hash $arg_a consistent; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 server 127.0.0.1:8081; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 server 127.0.0.1:8083 weight=10; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 upstream c { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 hash $arg_a consistent; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 server 127.0.0.1:8081; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 server 127.0.0.1:8082; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 server 127.0.0.1:8083; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 upstream c2 { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 hash $arg_a consistent; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 server 127.0.0.1:8081; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 server 127.0.0.1:8083; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 upstream bad { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 hash $arg_a; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 server 127.0.0.1:8081; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 server 127.0.0.1:8084; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 upstream cbad { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 hash $arg_a consistent; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 server 127.0.0.1:8081; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 server 127.0.0.1:8084; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 server { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 listen 127.0.0.1:8080; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 server_name localhost; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 location / { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 proxy_pass http://u; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 location /2 { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 proxy_pass http://u2; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 location /cw { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 proxy_pass http://cw; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 location /cw2 { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 proxy_pass http://cw2; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 location /c { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 proxy_pass http://c; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 location /c2 { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 proxy_pass http://c2; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 location /bad { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 proxy_pass http://bad; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 location /cbad { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 proxy_pass http://cbad; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 location /pnu { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 proxy_pass http://u/; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 proxy_next_upstream http_502; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 server { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 listen 127.0.0.1:8081; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 listen 127.0.0.1:8082; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 listen 127.0.0.1:8083; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 server_name localhost; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 add_header X-Port $server_port; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 location / { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 return 204; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 location /502 { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 if ($server_port = 8083) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 return 502; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 return 204; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 } |
457
4ceb2d12b7d2
Tests: speedup upstream_hash.t on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
411
diff
changeset
|
143 |
4ceb2d12b7d2
Tests: speedup upstream_hash.t on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
411
diff
changeset
|
144 server { |
4ceb2d12b7d2
Tests: speedup upstream_hash.t on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
411
diff
changeset
|
145 listen 127.0.0.1:8084; |
4ceb2d12b7d2
Tests: speedup upstream_hash.t on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
411
diff
changeset
|
146 server_name localhost; |
4ceb2d12b7d2
Tests: speedup upstream_hash.t on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
411
diff
changeset
|
147 return 444; |
4ceb2d12b7d2
Tests: speedup upstream_hash.t on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
411
diff
changeset
|
148 } |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 EOF |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 |
568
907e89fba9c3
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
457
diff
changeset
|
153 $t->run(); |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 ############################################################################### |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 # Ony requests for absent peer are moved to other peers if hash is consistent. |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 # Check this by comparing two upstreams with different number of peers. |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 ok(!cmp_peers([iter('/', 20)], [iter('/2', 20)], 8082), 'inconsistent'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 ok(cmp_peers([iter('/c', 20)], [iter('/c2', 20)], 8082), 'consistent'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 ok(cmp_peers([iter('/cw', 20)], [iter('/cw2', 20)], 8082), 'consistent weight'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 like(many('/?a=1', 10), qr/808\d: 10/, 'stable hash'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 like(many('/c?a=1', 10), qr/808\d: 10/, 'stable hash - consistent'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 my @res = iter('/', 10); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 is(@res, 10, 'all hashed peers'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 @res = grep { $_ != 8083 } @res; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 my @res2 = iter('/502', 10); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 is_deeply(\@res, \@res2, 'no proxy_next_upstream'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 isnt(@res2, 10, 'no proxy_next_upstream peers'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 is(iter('/pnu/502', 10), 10, 'proxy_next_upstream peers'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 @res = grep { $_ == 8081 } iter('/bad', 20); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 is(@res, 20, 'all hashed peers - bad'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 @res = grep { $_ == 8081 } iter('/cbad', 20); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 is(@res, 20, 'all hashed peers - bad consistent'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 ############################################################################### |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 # Returns true if two arrays follow consistency, i.e., they may only differ |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 # by @args present in $p, but absent in $p2, for the same indices. |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 sub cmp_peers { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 my ($p, $p2, @args) = @_; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 for my $i (0 .. $#$p) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 next if @{$p}[$i] == @{$p2}[$i]; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 next if (grep $_ == @{$p}[$i], @args); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 return 0; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
198 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 return 1; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 # series of requests, each with unique hash key |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 sub iter { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 my ($uri, $count) = @_; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 my @res; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
207 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
208 for my $i (1 .. $count) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
209 if (http_get("$uri/?a=$i") =~ /X-Port: (\d+)/) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 push @res, $1 if defined $1; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
212 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
213 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
214 return @res; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
215 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
216 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
217 sub many { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
218 my ($uri, $count) = @_; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
219 my %ports; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
220 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
221 for my $i (1 .. $count) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
222 if (http_get($uri) =~ /X-Port: (\d+)/) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
223 $ports{$1} = 0 unless defined $ports{$1}; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
224 $ports{$1}++; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
225 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
226 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
227 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
228 return join ', ', map { $_ . ": " . $ports{$_} } sort keys %ports; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
229 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
230 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
231 ############################################################################### |