Mercurial > hg > nginx-tests
annotate stream_limit_conn_complex.t @ 1690:29f0e926c15f
Tests: removed HTTP/2 Upgrade-based negotiation tests.
The HTTP/1.1 Upgrade mechanism is no longer specified in the current http2bis.
See also: https://github.com/BishopFox/h2csmuggler
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 25 May 2021 16:50:14 +0300 |
parents | f3ba4c74de31 |
children |
rev | line source |
---|---|
966
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream limit_conn module. |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@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/) |
966
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 events { |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 } |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1251
diff
changeset
|
36 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1251
diff
changeset
|
37 |
966
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 limit_conn_zone $binary_remote_addr$server_port zone=zone:1m; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
966
diff
changeset
|
41 listen 127.0.0.1:8080; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
966
diff
changeset
|
42 proxy_pass 127.0.0.1:8084; |
966
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 limit_conn zone 1; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 } |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
966
diff
changeset
|
47 listen 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
966
diff
changeset
|
48 proxy_pass 127.0.0.1:8084; |
966
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 limit_conn zone 1; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 http { |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 %%TEST_GLOBALS_HTTP%% |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
966
diff
changeset
|
57 listen 127.0.0.1:8084; |
966
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 server_name localhost; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 location / { } |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 } |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 EOF |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 $t->write_file('index.html', ''); |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
67 $t->run()->plan(4); |
966
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 ############################################################################### |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
966
diff
changeset
|
71 like(get(port(8080)), qr/200 OK/, 'passed'); |
966
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 my $s = http(<<EOF, start => 1, sleep => 0.2); |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 GET / HTTP/1.0 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 EOF |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 ok($s, 'long connection'); |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
966
diff
changeset
|
79 is(get(port(8080)), undef, 'rejected same key'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
966
diff
changeset
|
80 like(get(port(8081)), qr/200 OK/, 'passed different key'); |
966
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 ############################################################################### |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 sub get { |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 my $port = shift; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 my $s = IO::Socket::INET->new( |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 Proto => 'tcp', |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 PeerAddr => "127.0.0.1:$port" |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 ) |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 or die "Can't connect to nginx: $!\n"; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 my $r = http_get('/', socket => $s); |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 if (!$r) { |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 $r = undef; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 } |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 return $r; |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 } |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
3ac72d59430b
Tests: stream limit_conn tests with complex value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 ############################################################################### |