Skip to content

Commit fea22d5

Browse files
committed
Tests: added upstream max_conns tests with hash balancer.
1 parent 3ef6792 commit fea22d5

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

stream_upstream_max_conns.t

+27-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ select STDERR; $| = 1;
2525
select STDOUT; $| = 1;
2626

2727
my $t = Test::Nginx->new()->has(qw/stream stream_upstream_least_conn/)
28-
->plan(12);
28+
->has(qw/stream_upstream_hash/)->plan(14);
2929

3030
$t->write_file_expand('nginx.conf', <<'EOF');
3131
@@ -89,6 +89,17 @@ stream {
8989
server 127.0.0.1:8082 backup max_conns=3;
9090
}
9191
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+
92103
server {
93104
listen 127.0.0.1:8086;
94105
proxy_pass u_unlim;
@@ -143,6 +154,16 @@ stream {
143154
listen 127.0.0.1:8096;
144155
proxy_pass u_lc_backup_lim;
145156
}
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;
166+
}
146167
}
147168
148169
EOF
@@ -207,6 +228,11 @@ is(peers(8095, '/u_lc_backup', 6), "$p1 $p1 $p2 $p2 $p2 $p2",
207228
is(peers(8096, '/u_lc_backup_lim', 6), "$p1 $p1 $p2 $p2 $p2 ",
208229
'least_conn backup limited');
209230

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');
235+
210236
###############################################################################
211237

212238
sub peers {

upstream_max_conns.t

+17-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ select STDERR; $| = 1;
2424
select STDOUT; $| = 1;
2525

2626
my $t = Test::Nginx->new()->has(qw/http proxy rewrite upstream_least_conn/)
27-
->has(qw/upstream_ip_hash/)->plan(14);
27+
->has(qw/upstream_ip_hash upstream_hash/)->plan(16);
2828

2929
$t->write_file_expand('nginx.conf', <<'EOF');
3030
@@ -104,6 +104,17 @@ http {
104104
server 127.0.0.1:8082 max_conns=2;
105105
}
106106
107+
upstream u_hash {
108+
hash $remote_addr;
109+
server 127.0.0.1:8081 max_conns=1;
110+
server 127.0.0.1:8082 max_conns=2;
111+
}
112+
upstream u_chash {
113+
hash $remote_addr consistent;
114+
server 127.0.0.1:8081 max_conns=1;
115+
server 127.0.0.1:8082 max_conns=2;
116+
}
117+
107118
server {
108119
listen 127.0.0.1:8084;
109120
server_name localhost;
@@ -200,6 +211,11 @@ is(peers('/u_lc_backup_lim', 6), "$p1 $p1 $p2 $p2 $p2 ",
200211

201212
is(parallel('/u_ih', 4), "$p1: 1, $p2: 2", 'ip_hash');
202213

214+
# hash balancer tests
215+
216+
is(parallel('/u_hash', 4), "$p1: 1, $p2: 2", 'hash');
217+
is(parallel('/u_chash', 4), "$p1: 1, $p2: 2", 'hash consistent');
218+
203219
###############################################################################
204220

205221
sub peers {

0 commit comments

Comments
 (0)