annotate upstream_max_conns.t @ 1571:1b4ceab9cb1c

Tests: fixed ssl_certificate.t with LibreSSL client. Net::SSLeay::connect() that manages TLS handshake could return unexpected error when receiving server alert, as seen in server certificate tests if it could not been selected. Typically, it returns the expected error -1, but with certain libssl implementations it can be 0, as explained below. The error is propagated from libssl's SSL_connect(), which is usually -1. In modern OpenSSL versions, it is the default error code used in the state machine returned when something went wrong with parsing TLS message header. In versions up to OpenSSL 1.0.2, with SSLv23_method() used by default, -1 is the only error code in the ssl_connect() method implementation which is used as well if receiving alert while parsing ServerHello. BoringSSL also seems to return -1. But it is not so with LibreSSL that returns zero. Previously, tests failed with client built with LibreSSL with SSLv3 removed. Here, the error is propagated directly from ssl_read_bytes() method, which is always implemented as ssl3_read_bytes() in all TLS methods. It could be also seen with OpenSSL up to 1.0.2 with non-default methods explicitly set.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 29 May 2020 23:10:20 +0300
parents 3c101e516213
children
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/)
1394
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
27 ->has(qw/upstream_ip_hash upstream_hash/)->plan(16);
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;
1393
23cf08e9d2a2 Tests: fixed upstream max_conns test with ip_hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
104 server 127.0.0.1:8082 max_conns=2;
1041
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
1394
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
107 upstream u_hash {
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
108 hash $remote_addr;
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
109 server 127.0.0.1:8081 max_conns=1;
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
110 server 127.0.0.1:8082 max_conns=2;
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
111 }
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
112 upstream u_chash {
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
113 hash $remote_addr consistent;
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
114 server 127.0.0.1:8081 max_conns=1;
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
115 server 127.0.0.1:8082 max_conns=2;
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
116 }
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
117
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 server {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 listen 127.0.0.1:8084;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 server_name localhost;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 location / {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 return 444;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 }
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 server {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 listen 127.0.0.1:8080;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 server_name localhost;
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 proxy_http_version 1.1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 proxy_set_header Connection "";
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 proxy_buffering off;
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 location /u {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136 proxy_pass http:/$uri;
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
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139 location /close {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 proxy_pass http://127.0.0.1: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
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145 EOF
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147 $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
148 $t->run();
1041
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 $t->waitforsocket('127.0.0.1:' . port(8081));
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 $t->waitforsocket('127.0.0.1:' . port(8082));
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 $t->waitforsocket('127.0.0.1:' . port(8085));
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154 ###############################################################################
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156 my @ports = my ($p1, $p2) = (port(8081), port(8082));
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 # two peers without max_conns
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160 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
161
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162 # reopen connection to test connection subtraction
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
164 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
165 http_get('/u_lim/close');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
166 push @s, http_get_multi('/u_lim', 1, 1.1);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
167 http_get('/closeall');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
169 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
170
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
171 # 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
172
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
173 is(parallel('/u_lim', 4), "$p1: 3", 'single');
1041
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 # limited peer with backup peer
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(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
178
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 # peer and backup peer, both limited
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(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
182
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183 # all peers limited
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_two', 4), "$p1: 1, $p2: 1", 'all peers');
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 # subset of peers limited
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_some', 4), "$p1: 1, $p2: 3", 'some peers');
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 # 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
192
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193 is(parallel('/u_weight', 4), "$p1: 1, $p2: 3", 'weight');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 # peers with equal server value aggregate max_conns limit
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197 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
198
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199 # connections to peer selected with proxy_next_upstream are counted
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
200
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
201 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
202
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
203 # least_conn balancer tests
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
204
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
205 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
206 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
207 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
208 'least_conn backup limited');
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 # ip_hash balancer tests
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
211
1393
23cf08e9d2a2 Tests: fixed upstream max_conns test with ip_hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
212 is(parallel('/u_ih', 4), "$p1: 1, $p2: 2", 'ip_hash');
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
213
1394
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
214 # hash balancer tests
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
215
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
216 is(parallel('/u_hash', 4), "$p1: 1, $p2: 2", 'hash');
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
217 is(parallel('/u_chash', 4), "$p1: 1, $p2: 2", 'hash consistent');
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1393
diff changeset
218
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
219 ###############################################################################
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
220
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
221 sub peers {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
222 my ($uri, $count) = @_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
223
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
224 my @sockets = http_get_multi($uri, $count, 1.1);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
225 http_get('/closeall');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
226
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
227 join ' ', map { /X-Port: (\d+)/ && $1 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
228 map { http_end $_ } (@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
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
231 sub parallel {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
232 my ($uri, $count) = @_;
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 my @sockets = http_get_multi($uri, $count);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
235 for (1 .. 20) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
236 last if IO::Select->new(@sockets)->can_read(3) == $count;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
237 select undef, undef, undef, 0.01;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
238 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
239 http_get('/closeall');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
240 return http_end_multi(\@sockets);
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
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
243 sub http_get_multi {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
244 my ($uri, $count, $wait) = @_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
245 my @sockets;
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 for (0 .. $count - 1) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
248 $sockets[$_] = http_get($uri, start => 1);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
249 IO::Select->new($sockets[$_])->can_read($wait) if $wait;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
250 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
251
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
252 return @sockets;
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 sub http_end_multi {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
256 my ($sockets) = @_;
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
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
259 for my $sock (@$sockets) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
260 if (http_end($sock) =~ /X-Port: (\d+)/) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
261 $ports{$1} = 0 unless defined $ports{$1};
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
262 $ports{$1}++;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
263 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
264 close $sock;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
265 }
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 my @keys = map { my $p = $_; grep { $p == $_ } keys %ports } @ports;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
268 return join ', ', map { $_ . ": " . $ports{$_} } @keys;
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 ###############################################################################
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
272
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
273 sub http_daemon {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
274 my (@ports) = @_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
275 my (@socks, @clients);
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 for my $port (@ports) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
278 my $server = IO::Socket::INET->new(
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
279 Proto => 'tcp',
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
280 LocalHost => "127.0.0.1:$port",
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
281 Listen => 42,
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
282 Reuse => 1
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
283 )
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
284 or die "Can't create listening socket: $!\n";
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
285 push @socks, $server;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
286 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
287
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
288 my $sel = IO::Select->new(@socks);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
289 my $skip = 4;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
290 my $count = 0;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
291
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
292 local $SIG{PIPE} = 'IGNORE';
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 OUTER:
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
295 while (my @ready = $sel->can_read) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
296 foreach my $fh (@ready) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
297 if (grep $_ == $fh, @socks) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
298 my $new = $fh->accept;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
299 $new->autoflush(1);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
300 $sel->add($new);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
301 $count++;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
302
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
303 } else {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
304 my @busy = grep { $_->sockport() } @ready;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
305
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
306 # finish other handles
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
307 if ($fh->sockport() == port(8085) && @busy > 1
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
308 && grep $_->sockport() != port(8085),
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
309 @busy)
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
310 {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
311 next;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
312 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
313
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
314 # late events in other handles
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
315 if ($fh->sockport() == port(8085) && @busy == 1
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
316 && $count > 1 && $skip-- > 0)
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
317 {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
318 select undef, undef, undef, 0.1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
319 next OUTER;
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 my $rv = process_socket($fh, \@clients);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
323 if ($rv == 1) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
324 $sel->remove($fh);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
325 $fh->close;
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 if ($rv == 2) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
328 for (@clients) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
329 $sel->remove($_);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
330 $_->close;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
331 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
332 $sel->remove($fh);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
333 $fh->close;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
334 $skip = 4;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
335 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
336 $count--;
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 }
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 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
341
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
342 # Returns true to close connection
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
343
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
344 sub process_socket {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
345 my ($client, $saved) = @_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
346 my $port = $client->sockport();
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 my $headers = '';
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
349 my $uri = '';
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 while (<$client>) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
352 $headers .= $_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
353 last if (/^\x0d?\x0a?$/);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
354 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
355 return 1 if $headers eq '';
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 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
358 return 1 if $uri eq '';
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
359
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
360 Test::Nginx::log_core('||', "$port: response, 200");
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
361 print $client <<EOF;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
362 HTTP/1.1 200 OK
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
363 X-Port: $port
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
364
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
365 OK
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
366 EOF
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
367
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
368 return 2 if $uri =~ /closeall/;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
369 return 1 if $uri =~ /close/;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
370
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
371 push @$saved, $client;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
372 return 0;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
373 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
374
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
375 ###############################################################################