Mercurial > hg > nginx-tests
annotate stream_limit_conn.t @ 1276:490691c45b3f
Tests: style.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 31 Jan 2018 13:00:34 +0300 |
parents | 196d33c2bb45 |
children | f3ba4c74de31 |
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 { |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 limit_conn_zone $binary_remote_addr zone=zone:1m; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 limit_conn_zone $binary_remote_addr zone=zone2:1m; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
40 listen 127.0.0.1:8080; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
41 proxy_pass 127.0.0.1:8084; |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 limit_conn zone 1; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
43 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
46 listen 127.0.0.1:8085; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
47 proxy_pass 127.0.0.1:8084; |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 limit_conn zone 5; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
52 listen 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
53 proxy_pass 127.0.0.1:8084; |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 limit_conn zone2 1; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
58 listen 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
59 proxy_pass 127.0.0.1:8080; |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 limit_conn zone2 1; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
64 listen 127.0.0.1:8083; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
65 proxy_pass 127.0.0.1:8080; |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 limit_conn zone 1; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 } |
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 http { |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 %%TEST_GLOBALS_HTTP%% |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
74 listen 127.0.0.1:8084; |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 server_name localhost; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 location / { } |
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 } |
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 EOF |
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 $t->write_file('index.html', ''); |
866
5048b8f0fedd
Tests: removed try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
619
diff
changeset
|
84 $t->run(); |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 ############################################################################### |
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 like(get(), qr/200 OK/, 'passed'); |
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 # same and other zones |
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 my $s = http(<<EOF, start => 1, sleep => 0.2); |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
93 GET / HTTP/1.0 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
94 EOF |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
95 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
96 ok($s, 'long connection'); |
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 is(get(), undef, 'rejected same zone'); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
99 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
|
100 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
|
101 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
102 ok(http(<<EOF, socket => $s), 'long connection closed'); |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
103 Host: localhost |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
104 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
105 EOF |
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 # zones proxy chain |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
108 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
109 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
|
110 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
|
111 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
112 ############################################################################### |
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 sub get { |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
115 my $peer = shift; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
116 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
117 my $r = http_get('/', socket => getconn($peer)); |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
118 if (!$r) { |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
119 $r = undef; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
120 } |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
121 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
122 return $r; |
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 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
125 sub getconn { |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
126 my $peer = shift; |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
127 my $s = IO::Socket::INET->new( |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
128 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
129 PeerAddr => $peer || '127.0.0.1:' . port(8080) |
619
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
130 ) |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
131 or die "Can't connect to nginx: $!\n"; |
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 return $s; |
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 |
58a67c40a761
Tests: stream limit conn tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
136 ############################################################################### |