Mercurial > hg > nginx-tests
annotate upstream_hash.t @ 431:05c46688b54b
Tests: ssl_password_file.t fixes.
Make sure to always specify listen socket in all servers as the
default vary (under root, nginx will try to listen on 80). Make sure
to detect if an https request was processed by http.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 09 Jul 2014 05:19:51 +0400 |
parents | 17c5a1cc8757 |
children | 4ceb2d12b7d2 |
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 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite upstream_hash/); |
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 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 EOF |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 $t->try_run('no upstream hash')->plan(11); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 |
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 # 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
|
152 # Check this by comparing two upstreams with different number of peers. |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 ok(!cmp_peers([iter('/', 20)], [iter('/2', 20)], 8082), 'inconsistent'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 ok(cmp_peers([iter('/c', 20)], [iter('/c2', 20)], 8082), 'consistent'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 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
|
157 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 like(many('/?a=1', 10), qr/808\d: 10/, 'stable hash'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 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
|
160 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 my @res = iter('/', 10); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 is(@res, 10, 'all hashed peers'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 @res = grep { $_ != 8083 } @res; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 my @res2 = iter('/502', 10); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 is_deeply(\@res, \@res2, 'no proxy_next_upstream'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 isnt(@res2, 10, 'no proxy_next_upstream 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 is(iter('/pnu/502', 10), 10, 'proxy_next_upstream peers'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 @res = grep { $_ == 8081 } iter('/bad', 20); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 is(@res, 20, 'all hashed peers - bad'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 @res = grep { $_ == 8081 } iter('/cbad', 20); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 is(@res, 20, 'all hashed peers - bad consistent'); |
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 ############################################################################### |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 # 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
|
182 # 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
|
183 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 sub cmp_peers { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 my ($p, $p2, @args) = @_; |
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 for my $i (0 .. $#$p) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 next if @{$p}[$i] == @{$p2}[$i]; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 next if (grep $_ == @{$p}[$i], @args); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 return 0; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 } |
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 return 1; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 # series of requests, each with unique hash key |
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 sub iter { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 my ($uri, $count) = @_; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 my @res; |
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 for my $i (1 .. $count) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 if (http_get("$uri/?a=$i") =~ /X-Port: (\d+)/) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 push @res, $1 if defined $1; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 } |
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 return @res; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
209 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 sub many { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
212 my ($uri, $count) = @_; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
213 my %ports; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
214 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
215 for my $i (1 .. $count) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
216 if (http_get($uri) =~ /X-Port: (\d+)/) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
217 $ports{$1} = 0 unless defined $ports{$1}; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
218 $ports{$1}++; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
219 } |
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 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
222 return join ', ', map { $_ . ": " . $ports{$_} } sort keys %ports; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
223 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
224 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
225 ############################################################################### |