Mercurial > hg > nginx-tests
annotate upstream_random.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 144c6ce732e4 |
children |
rev | line source |
---|---|
1350
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for upstream random balancer module. |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx qw/ :DEFAULT http_end /; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy upstream_zone upstream_random/) |
1535
144c6ce732e4
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1427
diff
changeset
|
26 ->plan(12)->write_file_expand('nginx.conf', <<'EOF'); |
1350
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 worker_processes 2; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 upstream u { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 zone z 1m; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 random; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 server 127.0.0.1:8081; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server 127.0.0.1:8082; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 server 127.0.0.1:8083 down; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 upstream lc { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 zone lc 1m; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 random two; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 server 127.0.0.1:8081; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server 127.0.0.1:8082; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 upstream w { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 zone w 1m; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 random two least_conn; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 server 127.0.0.1:8081; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 server 127.0.0.1:8082 weight=2; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 upstream mc { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 zone mc 1m; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 random; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 server 127.0.0.1:8081 max_conns=2; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 server 127.0.0.1:8082 max_conns=1; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 upstream mc2 { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 zone mc 1m; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 random two; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 server 127.0.0.1:8081 max_conns=2; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 server 127.0.0.1:8082 max_conns=1; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 upstream one { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 random; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 server 127.0.0.1:8081; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 upstream two { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 random two; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 server 127.0.0.1:8081; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 upstream zone { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 zone z 1m; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 random; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 server 127.0.0.1:8081; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 upstream ztwo { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 zone z 1m; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 random two; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 server 127.0.0.1:8081; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 server { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 listen 127.0.0.1:8080; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 server_name localhost; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 location / { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 proxy_pass http://u; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 location /lc/ { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 proxy_pass http://lc/; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 location /w { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 proxy_pass http://w; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 location /mc/ { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 proxy_pass http://mc/; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 location /mc2/ { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 proxy_pass http://mc2/; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 location /one { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 proxy_pass http://one; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 location /two { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 proxy_pass http://two; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 location /zone { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 proxy_pass http://zone; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 location /ztwo { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 proxy_pass http://ztwo; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 EOF |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 $t->run_daemon(\&http_daemon, port(8081)); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 $t->run_daemon(\&http_daemon, port(8082)); |
1535
144c6ce732e4
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1427
diff
changeset
|
143 $t->run(); |
1350
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 $t->waitforsocket('127.0.0.1:' . port(8081)); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 $t->waitforsocket('127.0.0.1:' . port(8082)); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 ############################################################################### |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 my @ports = my ($port1, $port2) = (port(8081), port(8082)); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 like(http_get('/'), qr/X-Port: ($port1|$port2)/, 'random'); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 like(http_get('/lc/'), qr/X-Port: ($port1|$port2)/, 'random two'); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 |
1369
a37d8526e691
Tests: adjusted delay in upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1350
diff
changeset
|
155 my $s = http_get('/lc/w', start => 1, sleep => 0.5); |
1350
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 my $r = http_get('/lc/'); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 my ($p) = http_end($s) =~ /X-Port: (\d+)/; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 like($r, qr/X-Port: (?!$p)/, 'random wait'); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 SKIP: { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 skip 'long test', 3 unless $ENV{TEST_NGINX_UNSAFE}; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 is(parallel('/w', 3), "$port1: 1, $port2: 2", 'random weight'); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 is(parallel('/mc/w', 4), "$port1: 2, $port2: 1", 'max_conns'); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 is(parallel('/mc2/w', 4), "$port1: 2, $port2: 1", 'max_conns two'); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 # single variants |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 like(http_get('/one'), qr/X-Port: $port1/, 'single one'); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 like(http_get('/two'), qr/X-Port: $port1/, 'single two'); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 like(http_get('/zone'), qr/X-Port: $port1/, 'zone one'); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 like(http_get('/ztwo'), qr/X-Port: $port1/, 'zone two'); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 like(many('/close', 10), qr/$port2: 10/, 'failures'); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 like(many('/lc/close', 10), qr/$port2: 10/, 'failures two'); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 ############################################################################### |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 sub many { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 my ($uri, $count, %opts) = @_; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 my %ports; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 for (1 .. $count) { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 if (http_get($uri) =~ /X-Port: (\d+)/) { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 $ports{$1} = 0 unless defined $ports{$1}; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 $ports{$1}++; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 select undef, undef, undef, $opts{delay} if $opts{delay}; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 my @keys = map { my $p = $_; grep { $p == $_ } keys %ports } @ports; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 return join ', ', map { $_ . ": " . $ports{$_} } @keys; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
198 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 sub parallel { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 my ($uri, $n) = @_; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 my %ports; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 my @s = map { http_get($uri, start => 1, sleep => 0.1) } (1 .. $n); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 for (@s) { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 if (http_end($_) =~ /X-Port: (\d+)/) { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
207 $ports{$1} = 0 unless defined $ports{$1}; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
208 $ports{$1}++; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
209 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
212 my @keys = map { my $p = $_; grep { $p == $_ } keys %ports } @ports; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
213 return join ', ', map { $_ . ": " . $ports{$_} } @keys; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
214 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
215 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
216 ############################################################################### |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
217 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
218 sub http_daemon { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
219 my ($port) = @_; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
220 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
221 my $server = IO::Socket::INET->new( |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
222 Proto => 'tcp', |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
223 LocalHost => '127.0.0.1', |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
224 LocalPort => $port, |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
225 Listen => 5, |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
226 Reuse => 1 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
227 ) |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
228 or die "Can't create listening socket: $!\n"; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
229 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
230 local $SIG{PIPE} = 'IGNORE'; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
231 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
232 while (my $client = $server->accept()) { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
233 $client->autoflush(1); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
234 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
235 my $headers = ''; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
236 my $uri = ''; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
237 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
238 while (<$client>) { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
239 $headers .= $_; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
240 last if (/^\x0d?\x0a?$/); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
241 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
242 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
243 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
244 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
245 if ($uri eq '/w') { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
246 Test::Nginx::log_core('||', "$port: sleep(2.5)"); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
247 select undef, undef, undef, 2.5; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
248 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
249 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
250 if ($uri eq '/close' && $port == port(8081)) { |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
251 next; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
252 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
253 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
254 Test::Nginx::log_core('||', "$port: response, 200"); |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
255 print $client <<EOF; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
256 HTTP/1.1 200 OK |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
257 Connection: close |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
258 X-Port: $port |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
259 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
260 OK |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
261 EOF |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
262 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
263 close $client; |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
264 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
265 } |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
266 |
fda743e92b31
Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
267 ############################################################################### |