Mercurial > hg > nginx-tests
annotate upstream_hash.t @ 1951:1867428f1673
Tests: fixed h3_limit_req.t spurious failures.
In the "reset stream - cancellation" test, HTTP/3 stream is closed without
sending the request body when the request is waiting in the limit_req
module, and this results in error 444. However, when the request is received
with some minor delay due to system load, it is not delayed by limit_req,
and the stream is closed during reading the request body, which results
in error 400 instead, breaking the test.
Fix is to introduce yet another request before the "reset stream" test,
so the stream in question is always delayed by limit_req.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 14 Mar 2024 02:25:49 +0300 |
parents | 5ac6efbe5552 |
children |
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 |
1481
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite upstream_hash/)->plan(15); |
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; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
41 server 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
42 server 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 server 127.0.0.1:8083; |
411
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; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
48 server 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
49 server 127.0.0.1:8083; |
411
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; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
54 server 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
55 server 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
56 server 127.0.0.1:8083 weight=10; |
411
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; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
61 server 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
62 server 127.0.0.1:8083 weight=10; |
411
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; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
67 server 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
68 server 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
69 server 127.0.0.1:8083; |
411
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; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
74 server 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
75 server 127.0.0.1:8083; |
411
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; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
80 server 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
81 server 127.0.0.1:8084; |
411
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; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
86 server 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
87 server 127.0.0.1:8084; |
411
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 { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
91 listen 127.0.0.1:8080; |
411
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 } |
1036
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
118 location /busy { |
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
119 proxy_pass http://bad/busy; |
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
120 add_header X-IP $upstream_addr always; |
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
121 } |
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
122 location /cbusy { |
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
123 proxy_pass http://cbad/busy; |
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
124 add_header X-IP $upstream_addr always; |
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
125 } |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 location /pnu { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 proxy_pass http://u/; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 proxy_next_upstream http_502; |
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 } |
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 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
133 listen 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
134 listen 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
135 listen 127.0.0.1:8083; |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 server_name localhost; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 add_header X-Port $server_port; |
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 location / { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 return 204; |
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 location /502 { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
145 if ($server_port = %%PORT_8083%%) { |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 return 502; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 return 204; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 } |
1036
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
150 |
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
151 location /busy { |
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
152 return 444; |
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
153 } |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 } |
457
4ceb2d12b7d2
Tests: speedup upstream_hash.t on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
411
diff
changeset
|
155 |
4ceb2d12b7d2
Tests: speedup upstream_hash.t on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
411
diff
changeset
|
156 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
157 listen 127.0.0.1:8084; |
457
4ceb2d12b7d2
Tests: speedup upstream_hash.t on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
411
diff
changeset
|
158 server_name localhost; |
4ceb2d12b7d2
Tests: speedup upstream_hash.t on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
411
diff
changeset
|
159 return 444; |
4ceb2d12b7d2
Tests: speedup upstream_hash.t on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
411
diff
changeset
|
160 } |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 } |
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 EOF |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
568
907e89fba9c3
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
457
diff
changeset
|
165 $t->run(); |
411
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 ############################################################################### |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 |
1481
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
169 my @ports = my ($p1, $p2, $p3) = (port(8081), port(8082), port(8083)); |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
170 |
595
6cdfd177319b
Tests: fixed typos and misspellings.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
171 # Only requests for absent peer are moved to other peers if hash is consistent. |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 # Check this by comparing two upstreams with different number of peers. |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
174 ok(!cmp_peers([iter('/', 20)], [iter('/2', 20)], $p2), 'inconsistent'); |
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
175 ok(cmp_peers([iter('/c', 20)], [iter('/c2', 20)], $p2), 'consistent'); |
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
176 ok(cmp_peers([iter('/cw', 20)], [iter('/cw2', 20)], $p2), 'consistent weight'); |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
178 like(many('/?a=1', 10), qr/($p1|$p2|$p3): 10/, 'stable hash'); |
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
179 like(many('/c?a=1', 10), qr/($p1|$p2|$p3): 10/, 'stable hash - consistent'); |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 |
1481
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
181 # fallback to round-robin |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
182 |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
183 like(many('/?a=', 6), qr/$p1: 2, $p2: 2, $p3: 2/, 'empty key'); |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
184 like(many('/c?a=', 6), qr/$p1: 2, $p2: 2, $p3: 2/, 'empty key - consistent'); |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
185 |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 my @res = iter('/', 10); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 is(@res, 10, 'all hashed peers'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
190 @res = grep { $_ != $p3 } @res; |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 my @res2 = iter('/502', 10); |
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 is_deeply(\@res, \@res2, 'no proxy_next_upstream'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 isnt(@res2, 10, 'no proxy_next_upstream peers'); |
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 is(iter('/pnu/502', 10), 10, 'proxy_next_upstream peers'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
198 @res = grep { $_ == $p1 } iter('/bad', 20); |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 is(@res, 20, 'all hashed peers - bad'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
201 @res = grep { $_ == $p1 } iter('/cbad', 20); |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 is(@res, 20, 'all hashed peers - bad consistent'); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 |
1036
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
204 like(http_get('/busy'), qr/X-IP: 127.0.0.1:$p1, bad/, |
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
205 'upstream name - busy'); |
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
206 like(http_get('/cbusy'), qr/X-IP: 127.0.0.1:$p1, cbad/, |
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
207 'upstream name - busy consistent'); |
38ed3dda3279
Tests: $upstream_addr tests in hash module with no live upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
208 |
411
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 # 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
|
212 # 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
|
213 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
214 sub cmp_peers { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
215 my ($p, $p2, @args) = @_; |
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 for my $i (0 .. $#$p) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
218 next if @{$p}[$i] == @{$p2}[$i]; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
219 next if (grep $_ == @{$p}[$i], @args); |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
220 return 0; |
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 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
223 return 1; |
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 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
226 # series of requests, each with unique hash key |
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 sub iter { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
229 my ($uri, $count) = @_; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
230 my @res; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
231 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
232 for my $i (1 .. $count) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
233 if (http_get("$uri/?a=$i") =~ /X-Port: (\d+)/) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
234 push @res, $1 if defined $1; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
235 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
236 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
237 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
238 return @res; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
239 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
240 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
241 sub many { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
242 my ($uri, $count) = @_; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
243 my %ports; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
244 |
925
6bb1f2ccd386
Tests: removed unused variables.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
595
diff
changeset
|
245 for (1 .. $count) { |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
246 if (http_get($uri) =~ /X-Port: (\d+)/) { |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
247 $ports{$1} = 0 unless defined $ports{$1}; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
248 $ports{$1}++; |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
249 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
250 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
251 |
1481
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
252 my @keys = map { my $p = $_; grep { $p == $_ } keys %ports } @ports; |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
253 return join ', ', map { $_ . ": " . $ports{$_} } @keys; |
411
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
254 } |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
255 |
17c5a1cc8757
Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
256 ############################################################################### |