comparison stream_upstream_max_conns.t @ 1394:3c101e516213

Tests: added upstream max_conns tests with hash balancer.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 07 Nov 2018 15:07:23 +0300
parents 62f06d8dfc63
children f3ba4c74de31
comparison
equal deleted inserted replaced
1393:23cf08e9d2a2 1394:3c101e516213
23 23
24 select STDERR; $| = 1; 24 select STDERR; $| = 1;
25 select STDOUT; $| = 1; 25 select STDOUT; $| = 1;
26 26
27 my $t = Test::Nginx->new()->has(qw/stream stream_upstream_least_conn/) 27 my $t = Test::Nginx->new()->has(qw/stream stream_upstream_least_conn/)
28 ->plan(12); 28 ->has(qw/stream_upstream_hash/)->plan(14);
29 29
30 $t->write_file_expand('nginx.conf', <<'EOF'); 30 $t->write_file_expand('nginx.conf', <<'EOF');
31 31
32 %%TEST_GLOBALS%% 32 %%TEST_GLOBALS%%
33 33
87 least_conn; 87 least_conn;
88 server 127.0.0.1:8081 max_conns=2; 88 server 127.0.0.1:8081 max_conns=2;
89 server 127.0.0.1:8082 backup max_conns=3; 89 server 127.0.0.1:8082 backup max_conns=3;
90 } 90 }
91 91
92 upstream u_hash {
93 hash $remote_addr;
94 server 127.0.0.1:8081 max_conns=1;
95 server 127.0.0.1:8082 max_conns=2;
96 }
97 upstream u_chash {
98 hash $remote_addr consistent;
99 server 127.0.0.1:8081 max_conns=1;
100 server 127.0.0.1:8082 max_conns=2;
101 }
102
92 server { 103 server {
93 listen 127.0.0.1:8086; 104 listen 127.0.0.1:8086;
94 proxy_pass u_unlim; 105 proxy_pass u_unlim;
95 } 106 }
96 107
140 } 151 }
141 152
142 server { 153 server {
143 listen 127.0.0.1:8096; 154 listen 127.0.0.1:8096;
144 proxy_pass u_lc_backup_lim; 155 proxy_pass u_lc_backup_lim;
156 }
157
158 server {
159 listen 127.0.0.1:8097;
160 proxy_pass u_hash;
161 }
162
163 server {
164 listen 127.0.0.1:8098;
165 proxy_pass u_chash;
145 } 166 }
146 } 167 }
147 168
148 EOF 169 EOF
149 170
204 is(parallel(8094, '/u_lc', 4), "$p1: 1, $p2: 3", 'least_conn'); 225 is(parallel(8094, '/u_lc', 4), "$p1: 1, $p2: 3", 'least_conn');
205 is(peers(8095, '/u_lc_backup', 6), "$p1 $p1 $p2 $p2 $p2 $p2", 226 is(peers(8095, '/u_lc_backup', 6), "$p1 $p1 $p2 $p2 $p2 $p2",
206 'least_conn backup'); 227 'least_conn backup');
207 is(peers(8096, '/u_lc_backup_lim', 6), "$p1 $p1 $p2 $p2 $p2 ", 228 is(peers(8096, '/u_lc_backup_lim', 6), "$p1 $p1 $p2 $p2 $p2 ",
208 'least_conn backup limited'); 229 'least_conn backup limited');
230
231 # hash balancer tests
232
233 is(parallel(8097, '/u_hash', 4), "$p1: 1, $p2: 2", 'hash');
234 is(parallel(8098, '/u_chash', 4), "$p1: 1, $p2: 2", 'hash consistent');
209 235
210 ############################################################################### 236 ###############################################################################
211 237
212 sub peers { 238 sub peers {
213 my ($port, $uri, $count) = @_; 239 my ($port, $uri, $count) = @_;