annotate upstream_max_conns.t @ 1391:62f06d8dfc63

Tests: ported upstream max_conns tests to stream, reduced diffs.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 07 Nov 2018 14:49:34 +0300
parents 766bcbb632ee
children 23cf08e9d2a2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Nginx, Inc.
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5 # Tests for upstream module with max_conns feature.
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7 ###############################################################################
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9 use warnings;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use strict;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12 use Test::More;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14 use IO::Select;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use lib 'lib';
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use Test::Nginx qw/ :DEFAULT http_end /;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 ###############################################################################
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
26 my $t = Test::Nginx->new()->has(qw/http proxy rewrite upstream_least_conn/)
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
27 ->has(qw/upstream_ip_hash/)->plan(14);
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 $t->write_file_expand('nginx.conf', <<'EOF');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 %%TEST_GLOBALS%%
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 daemon off;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 events {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 http {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 %%TEST_GLOBALS_HTTP%%
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 upstream u_unlim {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 server 127.0.0.1:8081 max_conns=0;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 server 127.0.0.1:8082;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 upstream u_lim {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 server 127.0.0.1:8081 max_conns=3;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 upstream u_backup {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 server 127.0.0.1:8081 max_conns=2;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 server 127.0.0.1:8082 backup;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 upstream u_backup_lim {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 server 127.0.0.1:8081 max_conns=2;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 server 127.0.0.1:8082 backup max_conns=3;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 upstream u_two {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 server 127.0.0.1:8081 max_conns=1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 server 127.0.0.1:8082 max_conns=1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 upstream u_some {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 server 127.0.0.1:8081 max_conns=1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 server 127.0.0.1:8082;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 upstream u_many {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 server 127.0.0.1:8081 max_conns=1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 server 127.0.0.1:8081 max_conns=1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 server 127.0.0.1:8082;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 upstream u_weight {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 server 127.0.0.1:8081 weight=2 max_conns=1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 server 127.0.0.1:8082;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 upstream u_pnu {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 # special server to force next upstream
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 server 127.0.0.1:8084;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 server 127.0.0.1:8081 max_conns=1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 server 127.0.0.1:8082 max_conns=2;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 upstream u_lc {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 least_conn;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 server 127.0.0.1:8081 max_conns=1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 server 127.0.0.1:8082;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 upstream u_lc_backup {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 least_conn;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 server 127.0.0.1:8081 max_conns=2;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 server 127.0.0.1:8082 backup;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 upstream u_lc_backup_lim {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 least_conn;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 server 127.0.0.1:8081 max_conns=2;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 server 127.0.0.1:8082 backup max_conns=3;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 upstream u_ih {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 ip_hash;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 server 127.0.0.1:8081 max_conns=1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 server {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 listen 127.0.0.1:8084;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 server_name localhost;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 location / {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 return 444;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 server {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 listen 127.0.0.1:8080;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 server_name localhost;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 proxy_http_version 1.1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 proxy_set_header Connection "";
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 proxy_buffering off;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 location /u {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 proxy_pass http:/$uri;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 location /close {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 proxy_pass http://127.0.0.1:8085;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 EOF
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135 $t->run_daemon(\&http_daemon, port(8081), port(8082), port(8085));
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
136 $t->run();
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 $t->waitforsocket('127.0.0.1:' . port(8081));
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139 $t->waitforsocket('127.0.0.1:' . port(8082));
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 $t->waitforsocket('127.0.0.1:' . port(8085));
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142 ###############################################################################
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144 my @ports = my ($p1, $p2) = (port(8081), port(8082));
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 # two peers without max_conns
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148 is(parallel('/u_unlim?delay=0', 4), "$p1: 2, $p2: 2", 'unlimited');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150 # reopen connection to test connection subtraction
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
152 my @s = http_get_multi('/u_lim', 2, 1.1);
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153 http_get('/u_lim/close');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154 push @s, http_get_multi('/u_lim', 1, 1.1);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 http_get('/closeall');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
157 is(http_end_multi(\@s), "$p1: 3", 'conn subtraction');
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
158
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
159 # simple test with limited peer
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
160
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
161 is(parallel('/u_lim', 4), "$p1: 3", 'single');
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163 # limited peer with backup peer
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
165 is(peers('/u_backup', 6), "$p1 $p1 $p2 $p2 $p2 $p2", 'backup');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
166
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
167 # peer and backup peer, both limited
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169 is(peers('/u_backup_lim', 6), "$p1 $p1 $p2 $p2 $p2 ", 'backup limited');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 # all peers limited
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173 is(parallel('/u_two', 4), "$p1: 1, $p2: 1", 'all peers');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175 # subset of peers limited
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177 is(parallel('/u_some', 4), "$p1: 1, $p2: 3", 'some peers');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 # ensure that peer "weight" does not affect its max_conns limit
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
180
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
181 is(parallel('/u_weight', 4), "$p1: 1, $p2: 3", 'weight');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
182
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183 # peers with equal server value aggregate max_conns limit
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
184
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185 is(parallel('/u_many', 6), "$p1: 2, $p2: 4", 'equal peer');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187 # connections to peer selected with proxy_next_upstream are counted
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189 is(parallel('/u_pnu', 4), "$p1: 1, $p2: 2", 'proxy_next_upstream');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191 # least_conn balancer tests
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
192
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193 is(parallel('/u_lc', 4), "$p1: 1, $p2: 3", 'least_conn');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194 is(peers('/u_lc_backup', 6), "$p1 $p1 $p2 $p2 $p2 $p2", 'least_conn backup');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 is(peers('/u_lc_backup_lim', 6), "$p1 $p1 $p2 $p2 $p2 ",
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196 'least_conn backup limited');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 # ip_hash balancer tests
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
200 is(parallel('/u_ih', 4), "$p1: 1", 'ip_hash');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
201
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202 ###############################################################################
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
203
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
204 sub peers {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
205 my ($uri, $count) = @_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
206
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
207 my @sockets = http_get_multi($uri, $count, 1.1);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
208 http_get('/closeall');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
209
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
210 join ' ', map { /X-Port: (\d+)/ && $1 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
211 map { http_end $_ } (@sockets);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
212 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
213
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
214 sub parallel {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
215 my ($uri, $count) = @_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
216
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
217 my @sockets = http_get_multi($uri, $count);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
218 for (1 .. 20) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
219 last if IO::Select->new(@sockets)->can_read(3) == $count;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
220 select undef, undef, undef, 0.01;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
221 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
222 http_get('/closeall');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
223 return http_end_multi(\@sockets);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
224 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
225
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
226 sub http_get_multi {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
227 my ($uri, $count, $wait) = @_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
228 my @sockets;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
229
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
230 for (0 .. $count - 1) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
231 $sockets[$_] = http_get($uri, start => 1);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
232 IO::Select->new($sockets[$_])->can_read($wait) if $wait;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
233 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
234
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
235 return @sockets;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
236 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
237
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
238 sub http_end_multi {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
239 my ($sockets) = @_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
240 my %ports;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
241
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
242 for my $sock (@$sockets) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
243 if (http_end($sock) =~ /X-Port: (\d+)/) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
244 $ports{$1} = 0 unless defined $ports{$1};
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
245 $ports{$1}++;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
246 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
247 close $sock;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
248 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
249
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
250 my @keys = map { my $p = $_; grep { $p == $_ } keys %ports } @ports;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
251 return join ', ', map { $_ . ": " . $ports{$_} } @keys;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
252 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
253
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
254 ###############################################################################
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
255
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
256 sub http_daemon {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
257 my (@ports) = @_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
258 my (@socks, @clients);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
259
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
260 for my $port (@ports) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
261 my $server = IO::Socket::INET->new(
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
262 Proto => 'tcp',
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
263 LocalHost => "127.0.0.1:$port",
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
264 Listen => 42,
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
265 Reuse => 1
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
266 )
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
267 or die "Can't create listening socket: $!\n";
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
268 push @socks, $server;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
269 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
270
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
271 my $sel = IO::Select->new(@socks);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
272 my $skip = 4;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
273 my $count = 0;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
274
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
275 local $SIG{PIPE} = 'IGNORE';
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
276
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
277 OUTER:
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
278 while (my @ready = $sel->can_read) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
279 foreach my $fh (@ready) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
280 if (grep $_ == $fh, @socks) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
281 my $new = $fh->accept;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
282 $new->autoflush(1);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
283 $sel->add($new);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
284 $count++;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
285
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
286 } else {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
287 my @busy = grep { $_->sockport() } @ready;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
288
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
289 # finish other handles
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
290 if ($fh->sockport() == port(8085) && @busy > 1
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
291 && grep $_->sockport() != port(8085),
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
292 @busy)
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
293 {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
294 next;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
295 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
296
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
297 # late events in other handles
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
298 if ($fh->sockport() == port(8085) && @busy == 1
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
299 && $count > 1 && $skip-- > 0)
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
300 {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
301 select undef, undef, undef, 0.1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
302 next OUTER;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
303 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
304
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
305 my $rv = process_socket($fh, \@clients);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
306 if ($rv == 1) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
307 $sel->remove($fh);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
308 $fh->close;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
309 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
310 if ($rv == 2) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
311 for (@clients) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
312 $sel->remove($_);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
313 $_->close;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
314 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
315 $sel->remove($fh);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
316 $fh->close;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
317 $skip = 4;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
318 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
319 $count--;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
320 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
321 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
322 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
323 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
324
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
325 # Returns true to close connection
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
326
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
327 sub process_socket {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
328 my ($client, $saved) = @_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
329 my $port = $client->sockport();
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
330
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
331 my $headers = '';
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
332 my $uri = '';
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
333
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
334 while (<$client>) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
335 $headers .= $_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
336 last if (/^\x0d?\x0a?$/);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
337 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
338 return 1 if $headers eq '';
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
339
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
340 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
341 return 1 if $uri eq '';
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
342
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
343 Test::Nginx::log_core('||', "$port: response, 200");
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
344 print $client <<EOF;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
345 HTTP/1.1 200 OK
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
346 X-Port: $port
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
347
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
348 OK
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
349 EOF
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
350
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
351 return 2 if $uri =~ /closeall/;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
352 return 1 if $uri =~ /close/;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
353
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
354 push @$saved, $client;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
355 return 0;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
356 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
357
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
358 ###############################################################################