Mercurial > hg > nginx-tests
annotate stream_udp_limit_conn.t @ 1240:f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
When the testing script is run in verbose mode by prove that redirects stdout,
a garbled verbose mode line from backend can be produced that incorporates TAP
output of an individual test result, which eventually breaks the testing plan.
Notably, this happens when testing sending multiple frames if backend started
to respond before all frames were received. This is possible due to the line
boundary used as an indicator of last bytes to receive before starting to send.
The fix is to amend the only last frame of many specially, for that purpose.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 15 Nov 2017 20:16:09 +0300 |
parents | e4974af3fb12 |
children | c4f58dfe8207 |
rev | line source |
---|---|
868 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Andrey Zelenkov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for stream limit_conn module with datagrams. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 use Test::Nginx::Stream qw/ dgram /; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream stream_limit_conn udp/)->plan(9) |
868 | 27 ->write_file_expand('nginx.conf', <<'EOF'); |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 stream { | |
37 limit_conn_zone $binary_remote_addr zone=zone:1m; | |
38 limit_conn_zone $binary_remote_addr zone=zone2:1m; | |
39 | |
40 proxy_responses 1; | |
41 proxy_timeout 1s; | |
42 | |
43 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
44 listen 127.0.0.1:%%PORT_8981_UDP%% udp; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
45 proxy_pass 127.0.0.1:%%PORT_8980_UDP%%; |
868 | 46 |
47 limit_conn zone 1; | |
48 proxy_responses 2; | |
49 } | |
50 | |
51 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
52 listen 127.0.0.1:%%PORT_8982_UDP%% udp; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
53 proxy_pass 127.0.0.1:%%PORT_8980_UDP%%; |
868 | 54 limit_conn zone2 1; |
55 } | |
56 | |
57 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
58 listen 127.0.0.1:%%PORT_8983_UDP%% udp; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
59 proxy_pass 127.0.0.1:%%PORT_8980_UDP%%; |
868 | 60 limit_conn zone 5; |
61 } | |
62 | |
63 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
64 listen 127.0.0.1:%%PORT_8984_UDP%% udp; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
65 proxy_pass 127.0.0.1:%%PORT_8981_UDP%%; |
868 | 66 limit_conn zone2 1; |
67 } | |
68 | |
69 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
70 listen 127.0.0.1:%%PORT_8985_UDP%% udp; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
71 proxy_pass 127.0.0.1:%%PORT_8981_UDP%%; |
868 | 72 limit_conn zone 1; |
73 } | |
74 } | |
75 | |
76 EOF | |
77 | |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
78 $t->run(); |
868 | 79 $t->run_daemon(\&udp_daemon, $t); |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
80 $t->waitforfile($t->testdir . '/' . port(8980)); |
868 | 81 |
82 ############################################################################### | |
83 | |
84 # same and other zones | |
85 | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
86 my $s = dgram('127.0.0.1:' . port(8981)); |
868 | 87 |
88 is($s->io('1'), '1', 'passed'); | |
89 | |
936
e81cacf44cac
Tests: test rejecting new connection in stream_udp_limit_conn.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
935
diff
changeset
|
90 # if not all responses were sent to client, then new request |
e81cacf44cac
Tests: test rejecting new connection in stream_udp_limit_conn.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
935
diff
changeset
|
91 # in same socket will be treated as new connection |
e81cacf44cac
Tests: test rejecting new connection in stream_udp_limit_conn.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
935
diff
changeset
|
92 |
e81cacf44cac
Tests: test rejecting new connection in stream_udp_limit_conn.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
935
diff
changeset
|
93 is($s->io('1', read_timeout => 0.1), '', 'rejected new connection'); |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
94 is(dgram('127.0.0.1:' . port(8981))->io('1', read_timeout => 0.1), '', |
935
25a4b2fdd3fb
Tests: I/O timeout options introduced in Stream.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
95 'rejected same zone'); |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
96 is(dgram('127.0.0.1:' . port(8982))->io('1'), '1', 'passed different zone'); |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
97 is(dgram('127.0.0.1:' . port(8983))->io('1'), '1', 'passed same zone unlimited'); |
868 | 98 |
935
25a4b2fdd3fb
Tests: I/O timeout options introduced in Stream.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
99 sleep 1; # waiting for proxy_timeout to expire |
25a4b2fdd3fb
Tests: I/O timeout options introduced in Stream.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
100 |
25a4b2fdd3fb
Tests: I/O timeout options introduced in Stream.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
101 is($s->io('2', read => 2), '12', 'new connection after proxy_timeout'); |
868 | 102 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
103 is(dgram('127.0.0.1:' . port(8981))->io('2', read => 2), '12', 'passed 2'); |
868 | 104 |
105 # zones proxy chain | |
106 | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
107 is(dgram('127.0.0.1:' . port(8984))->io('1'), '1', 'passed proxy'); |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
108 is(dgram('127.0.0.1:' . port(8985))->io('1', read_timeout => 0.1), '', |
935
25a4b2fdd3fb
Tests: I/O timeout options introduced in Stream.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
109 'rejected proxy'); |
868 | 110 |
111 ############################################################################### | |
112 | |
113 sub udp_daemon { | |
114 my $t = shift; | |
115 | |
116 my $server = IO::Socket::INET->new( | |
117 Proto => 'udp', | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
118 LocalAddr => '127.0.0.1:' . port(8980), |
868 | 119 Reuse => 1, |
120 ) | |
121 or die "Can't create listening socket: $!\n"; | |
122 | |
123 # signal we are ready | |
124 | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
125 open my $fh, '>', $t->testdir() . '/' . port(8980); |
868 | 126 close $fh; |
127 | |
128 while (1) { | |
129 $server->recv(my $buffer, 65536); | |
130 $server->send($_) for (1 .. $buffer); | |
131 } | |
132 } | |
133 | |
134 ############################################################################### |