Mercurial > hg > nginx-tests
annotate stream_limit_conn.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | f3ba4c74de31 |
children |
rev | line source |
---|---|
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream limit_conn module. |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http stream stream_limit_conn/) |
866
5048b8f0fedd
Tests: removed try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
619
diff
changeset
|
26 ->plan(8)->write_file_expand('nginx.conf', <<'EOF'); |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 events { |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1020
diff
changeset
|
36 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1020
diff
changeset
|
37 |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 limit_conn_zone $binary_remote_addr zone=zone:1m; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 limit_conn_zone $binary_remote_addr zone=zone2:1m; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
40 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
41 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
42 listen 127.0.0.1:8080; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 proxy_pass 127.0.0.1:8084; |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 limit_conn zone 1; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
48 listen 127.0.0.1:8085; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
49 proxy_pass 127.0.0.1:8084; |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 limit_conn zone 5; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
54 listen 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
55 proxy_pass 127.0.0.1:8084; |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 limit_conn zone2 1; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
60 listen 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
61 proxy_pass 127.0.0.1:8080; |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 limit_conn zone2 1; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
66 listen 127.0.0.1:8083; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
67 proxy_pass 127.0.0.1:8080; |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 limit_conn zone 1; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 http { |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 %%TEST_GLOBALS_HTTP%% |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
76 listen 127.0.0.1:8084; |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 server_name localhost; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 location / { } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
80 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
82 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
83 EOF |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
84 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 $t->write_file('index.html', ''); |
866
5048b8f0fedd
Tests: removed try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
619
diff
changeset
|
86 $t->run(); |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 ############################################################################### |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
90 like(get(), qr/200 OK/, 'passed'); |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
91 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
92 # same and other zones |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
93 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
94 my $s = http(<<EOF, start => 1, sleep => 0.2); |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
95 GET / HTTP/1.0 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
96 EOF |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
97 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
98 ok($s, 'long connection'); |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
99 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
100 is(get(), undef, 'rejected same zone'); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
101 like(get('127.0.0.1:' . port(8081)), qr/200 OK/, 'passed different zone'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
102 like(get('127.0.0.1:' . port(8085)), qr/200 OK/, 'passed same zone unlimited'); |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
103 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
104 ok(http(<<EOF, socket => $s), 'long connection closed'); |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
105 Host: localhost |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
106 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
107 EOF |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
108 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
109 # zones proxy chain |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
110 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
111 like(get('127.0.0.1:' . port(8082)), qr/200 OK/, 'passed proxy'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
112 is(get('127.0.0.1:' . port(8083)), undef, 'rejected proxy'); |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
113 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
114 ############################################################################### |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
115 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
116 sub get { |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
117 my $peer = shift; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
118 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
119 my $r = http_get('/', socket => getconn($peer)); |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
120 if (!$r) { |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
121 $r = undef; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
122 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
123 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
124 return $r; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
125 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
126 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
127 sub getconn { |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
128 my $peer = shift; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
129 my $s = IO::Socket::INET->new( |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
130 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
131 PeerAddr => $peer || '127.0.0.1:' . port(8080) |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
132 ) |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
133 or die "Can't connect to nginx: $!\n"; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
134 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
135 return $s; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
136 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
137 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
138 ############################################################################### |