annotate stream_upstream_max_conns.t @ 1961:fe6f22da53ec default tip

Tests: tests for usage of discarded body. The client_max_body_size limit should be ignored when the request body is already discarded. In HTTP/1.x, this is done by checking the r->discard_body flag when the body is being discarded, and because r->headers_in.content_length_n is 0 when it's already discarded. This, however, does not happen with HTTP/2 and HTTP/3, and therefore "error_page 413" does not work without relaxing the limit. Further, with proxy_pass, r->headers_in.content_length_n is used to determine length of the request body, and therefore is not correct if discarding of the request body isn't yet complete. While discarding the request body, r->headers_in.content_length_n contains the rest of the body to discard (or, in case of chunked request body, the rest of the current chunk to discard). Similarly, the $content_length variable uses r->headers_in.content_length if available, and also incorrect. The $content_length variable is used when proxying with fastcgi_pass, grpc_pass, and uwsgi_pass (scgi_pass uses the value calculated based on the actual request body buffers, and therefore works correctly).
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 27 Apr 2024 18:55:50 +0300
parents f3ba4c74de31
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.
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
4 # (C) Sergey Kandaurov
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
6 # Tests for stream upstream module with max_conns feature.
1041
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
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 use IO::Select;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use lib 'lib';
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 use Test::Nginx qw/ :DEFAULT http_end /;
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
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDERR; $| = 1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 select STDOUT; $| = 1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
27 my $t = Test::Nginx->new()->has(qw/stream stream_upstream_least_conn/)
1394
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
28 ->has(qw/stream_upstream_hash/)->plan(14);
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 $t->write_file_expand('nginx.conf', <<'EOF');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 %%TEST_GLOBALS%%
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 daemon off;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 events {
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
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
39 stream {
1609
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1394
diff changeset
40 %%TEST_GLOBALS_STREAM%%
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1394
diff changeset
41
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 upstream u_unlim {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 server 127.0.0.1:8081 max_conns=0;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 server 127.0.0.1:8082;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 upstream u_lim {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 server 127.0.0.1:8081 max_conns=3;
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
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 upstream u_backup {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 server 127.0.0.1:8081 max_conns=2;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 server 127.0.0.1:8082 backup;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 upstream u_backup_lim {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 server 127.0.0.1:8081 max_conns=2;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 server 127.0.0.1:8082 backup max_conns=3;
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
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 upstream u_two {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 server 127.0.0.1:8081 max_conns=1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 server 127.0.0.1:8082 max_conns=1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 upstream u_some {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 server 127.0.0.1:8081 max_conns=1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 server 127.0.0.1:8082;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 upstream u_many {
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:8081 max_conns=1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 server 127.0.0.1:8082;
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
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 upstream u_weight {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 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
75 server 127.0.0.1:8082;
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
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 upstream u_lc {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 least_conn;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 server 127.0.0.1:8081 max_conns=1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 server 127.0.0.1:8082;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 upstream u_lc_backup {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 least_conn;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 server 127.0.0.1:8081 max_conns=2;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 server 127.0.0.1:8082 backup;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 upstream u_lc_backup_lim {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 least_conn;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 server 127.0.0.1:8081 max_conns=2;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 server 127.0.0.1:8082 backup max_conns=3;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
1394
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
94 upstream u_hash {
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
95 hash $remote_addr;
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
96 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: 1391
diff changeset
97 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: 1391
diff changeset
98 }
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
99 upstream u_chash {
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
100 hash $remote_addr consistent;
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
101 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: 1391
diff changeset
102 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: 1391
diff changeset
103 }
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
104
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
105 server {
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
106 listen 127.0.0.1:8086;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
107 proxy_pass u_unlim;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
108 }
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
109
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
110 server {
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
111 listen 127.0.0.1:8087;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
112 proxy_pass u_lim;
1041
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 {
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
116 listen 127.0.0.1:8088;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
117 proxy_pass u_backup;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
118 }
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
120 server {
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
121 listen 127.0.0.1:8089;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
122 proxy_pass u_backup_lim;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
123 }
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
124
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
125 server {
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
126 listen 127.0.0.1:8090;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
127 proxy_pass u_two;
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 }
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 server {
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
131 listen 127.0.0.1:8091;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
132 proxy_pass u_some;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
133 }
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
135 server {
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
136 listen 127.0.0.1:8092;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
137 proxy_pass u_many;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
138 }
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
139
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
140 server {
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
141 listen 127.0.0.1:8093;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
142 proxy_pass u_weight;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
143 }
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
145 server {
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
146 listen 127.0.0.1:8094;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
147 proxy_pass u_lc;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
148 }
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
150 server {
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
151 listen 127.0.0.1:8095;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
152 proxy_pass u_lc_backup;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
153 }
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
154
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
155 server {
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
156 listen 127.0.0.1:8096;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
157 proxy_pass u_lc_backup_lim;
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 }
1394
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
159
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
160 server {
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
161 listen 127.0.0.1:8097;
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
162 proxy_pass u_hash;
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
163 }
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
164
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
165 server {
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
166 listen 127.0.0.1:8098;
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
167 proxy_pass u_chash;
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
168 }
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169 }
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 EOF
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 $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
174 $t->run();
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176 $t->waitforsocket('127.0.0.1:' . port(8081));
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177 $t->waitforsocket('127.0.0.1:' . port(8082));
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178 $t->waitforsocket('127.0.0.1:' . port(8085));
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179
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
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
182 my @ports = my ($p1, $p2) = (port(8081), port(8082));
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
184 # two peers without max_conns
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
186 is(parallel(8086, '/u_unlim?delay=0', 4), "$p1: 2, $p2: 2", 'unlimited');
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188 # reopen connection to test connection subtraction
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
190 my @s = http_get_multi(8087, '/u_lim', 2, 1.1);
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
191 get(8087, '/close');
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
192 push @s, http_get_multi(8087, '/u_lim', 1, 1.1);
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
193 get(8085, '/closeall');
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
195 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
196
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
197 # 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
198
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
199 is(parallel(8087, '/u_lim', 4), "$p1: 3", 'single');
1041
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 # limited peer with backup peer
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
203 is(peers(8088, '/u_backup', 6), "$p1 $p1 $p2 $p2 $p2 $p2", 'backup');
1041
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 # peer and backup peer, both limited
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
206
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
207 is(peers(8089, '/u_backup_lim', 6), "$p1 $p1 $p2 $p2 $p2 ", 'backup limited');
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
208
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
209 # all peers limited
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
210
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
211 is(parallel(8090, '/u_two', 4), "$p1: 1, $p2: 1", 'all peers');
1041
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 # subset of peers limited
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
214
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
215 is(parallel(8091, '/u_some', 4), "$p1: 1, $p2: 3", 'some peers');
1041
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 # 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
218
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
219 is(parallel(8093, '/u_weight', 4), "$p1: 1, $p2: 3", 'weight');
1041
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 # peers with equal server value aggregate max_conns limit
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
222
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
223 is(parallel(8092, '/u_many', 6), "$p1: 2, $p2: 4", 'equal peer');
1041
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 # least_conn balancer tests
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
226
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
227 is(parallel(8094, '/u_lc', 4), "$p1: 1, $p2: 3", 'least_conn');
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
228 is(peers(8095, '/u_lc_backup', 6), "$p1 $p1 $p2 $p2 $p2 $p2",
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
229 'least_conn backup');
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
230 is(peers(8096, '/u_lc_backup_lim', 6), "$p1 $p1 $p2 $p2 $p2 ",
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
231 'least_conn backup limited');
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
232
1394
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
233 # hash balancer tests
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
234
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
235 is(parallel(8097, '/u_hash', 4), "$p1: 1, $p2: 2", 'hash');
3c101e516213 Tests: added upstream max_conns tests with hash balancer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1391
diff changeset
236 is(parallel(8098, '/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: 1391
diff changeset
237
1041
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
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
240 sub peers {
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
241 my ($port, $uri, $count) = @_;
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
242
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
243 my @sockets = http_get_multi($port, $uri, $count, 1.1);
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
244 get(8085, '/closeall');
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
245
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
246 join ' ', map { defined $_ && /X-Port: (\d+)/ && $1 }
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
247 map { http_end $_ } (@sockets);
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 sub parallel {
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
251 my ($port, $uri, $count) = @_;
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
252
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
253 my @sockets = http_get_multi($port, $uri, $count);
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
254 for (1 .. 20) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
255 last if IO::Select->new(@sockets)->can_read(3) == $count;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
256 select undef, undef, undef, 0.01;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
257 }
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
258 get(8085, '/closeall');
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
259 return http_end_multi(\@sockets);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
260 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
261
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
262 sub get {
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
263 my ($port, $uri, %opts) = @_;
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
264 my $s = IO::Socket::INET->new(
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
265 Proto => 'tcp',
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
266 PeerAddr => '127.0.0.1',
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
267 PeerPort => port($port),
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
268 )
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
269 or die "Can't connect to nginx: $!\n";
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
270
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
271 http_get($uri, socket => $s, %opts);
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
272 }
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
273
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
274 sub http_get_multi {
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
275 my ($port, $uri, $count, $wait) = @_;
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
276 my @sockets;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
277
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
278 for (0 .. $count - 1) {
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
279 $sockets[$_] = get($port, $uri, start => 1);
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
280 IO::Select->new($sockets[$_])->can_read($wait) if $wait;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
281 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
282
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
283 return @sockets;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
284 }
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 sub http_end_multi {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
287 my ($sockets) = @_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
288 my %ports;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
289
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
290 for my $sock (@$sockets) {
1391
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
291 my $r = http_end($sock);
62f06d8dfc63 Tests: ported upstream max_conns tests to stream, reduced diffs.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1251
diff changeset
292 if ($r && $r =~ /X-Port: (\d+)/) {
1041
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
293 $ports{$1} = 0 unless defined $ports{$1};
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
294 $ports{$1}++;
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 close $sock;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
297 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
298
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
299 my @keys = map { my $p = $_; grep { $p == $_ } keys %ports } @ports;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
300 return join ', ', map { $_ . ": " . $ports{$_} } @keys;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
301 }
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 ###############################################################################
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 sub http_daemon {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
306 my (@ports) = @_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
307 my (@socks, @clients);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
308
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
309 for my $port (@ports) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
310 my $server = IO::Socket::INET->new(
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
311 Proto => 'tcp',
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
312 LocalHost => "127.0.0.1:$port",
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
313 Listen => 42,
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
314 Reuse => 1
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
315 )
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
316 or die "Can't create listening socket: $!\n";
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
317 push @socks, $server;
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
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
320 my $sel = IO::Select->new(@socks);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
321 my $skip = 4;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
322 my $count = 0;
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 local $SIG{PIPE} = 'IGNORE';
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
325
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
326 OUTER:
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
327 while (my @ready = $sel->can_read) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
328 foreach my $fh (@ready) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
329 if (grep $_ == $fh, @socks) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
330 my $new = $fh->accept;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
331 $new->autoflush(1);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
332 $sel->add($new);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
333 $count++;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
334
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
335 } else {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
336 my @busy = grep { $_->sockport() } @ready;
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 # finish other handles
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
339 if ($fh->sockport() == port(8085) && @busy > 1
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
340 && grep $_->sockport() != port(8085),
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
341 @busy)
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 next;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
344 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
345
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
346 # late events in other handles
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
347 if ($fh->sockport() == port(8085) && @busy == 1
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
348 && $count > 1 && $skip-- > 0)
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
349 {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
350 select undef, undef, undef, 0.1;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
351 next OUTER;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
352 }
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 my $rv = process_socket($fh, \@clients);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
355 if ($rv == 1) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
356 $sel->remove($fh);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
357 $fh->close;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
358 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
359 if ($rv == 2) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
360 for (@clients) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
361 $sel->remove($_);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
362 $_->close;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
363 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
364 $sel->remove($fh);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
365 $fh->close;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
366 $skip = 4;
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 $count--;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
369 }
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 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
372 }
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 # Returns true to close connection
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
375
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
376 sub process_socket {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
377 my ($client, $saved) = @_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
378 my $port = $client->sockport();
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
379
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
380 my $headers = '';
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
381 my $uri = '';
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
382
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
383 while (<$client>) {
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
384 $headers .= $_;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
385 last if (/^\x0d?\x0a?$/);
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
386 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
387 return 1 if $headers eq '';
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
388
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
389 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
390 return 1 if $uri eq '';
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
391
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
392 Test::Nginx::log_core('||', "$port: response, 200");
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
393 print $client <<EOF;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
394 HTTP/1.1 200 OK
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
395 X-Port: $port
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
396
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
397 OK
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
398 EOF
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
399
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
400 return 2 if $uri =~ /closeall/;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
401 return 1 if $uri =~ /close/;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
402
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
403 push @$saved, $client;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
404 return 0;
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
405 }
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
406
187524328926 Tests: upstream max_conns tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
407 ###############################################################################