Mercurial > hg > nginx-tests
annotate stream_udp_limit_conn.t @ 1021:ebdf239722b9
Tests: relaxed proxy_cache_lock.t nolock tests to fix on Solaris.
Assumed that the order of responses being arrived in nolock case may be ignored.
An important part of such case is that the only last response should be cached.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 02 Sep 2016 12:17:35 +0300 |
parents | 196d33c2bb45 |
children | e4974af3fb12 |
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 { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
44 listen 127.0.0.1:%%PORT_8081_UDP%% udp; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 proxy_pass 127.0.0.1:%%PORT_8080_UDP%%; |
868 | 46 |
47 limit_conn zone 1; | |
48 proxy_responses 2; | |
49 } | |
50 | |
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:%%PORT_8082_UDP%% udp; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
53 proxy_pass 127.0.0.1:%%PORT_8080_UDP%%; |
868 | 54 limit_conn zone2 1; |
55 } | |
56 | |
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:%%PORT_8083_UDP%% udp; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
59 proxy_pass 127.0.0.1:%%PORT_8080_UDP%%; |
868 | 60 limit_conn zone 5; |
61 } | |
62 | |
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:%%PORT_8084_UDP%% udp; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
65 proxy_pass 127.0.0.1:%%PORT_8081_UDP%%; |
868 | 66 limit_conn zone2 1; |
67 } | |
68 | |
69 server { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
70 listen 127.0.0.1:%%PORT_8085_UDP%% udp; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
71 proxy_pass 127.0.0.1:%%PORT_8081_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); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
80 $t->waitforfile($t->testdir . '/' . port(8080)); |
868 | 81 |
82 ############################################################################### | |
83 | |
84 # same and other zones | |
85 | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
86 my $s = dgram('127.0.0.1:' . port(8081)); |
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'); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
94 is(dgram('127.0.0.1:' . port(8081))->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'); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
96 is(dgram('127.0.0.1:' . port(8082))->io('1'), '1', 'passed different zone'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
97 is(dgram('127.0.0.1:' . port(8083))->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 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
103 is(dgram('127.0.0.1:' . port(8081))->io('2', read => 2), '12', 'passed 2'); |
868 | 104 |
105 # zones proxy chain | |
106 | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
107 is(dgram('127.0.0.1:' . port(8084))->io('1'), '1', 'passed proxy'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
108 is(dgram('127.0.0.1:' . port(8085))->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', | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
118 LocalAddr => '127.0.0.1:' . port(8080), |
868 | 119 Reuse => 1, |
120 ) | |
121 or die "Can't create listening socket: $!\n"; | |
122 | |
123 # signal we are ready | |
124 | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
125 open my $fh, '>', $t->testdir() . '/' . port(8080); |
868 | 126 close $fh; |
127 | |
128 while (1) { | |
129 $server->recv(my $buffer, 65536); | |
130 $server->send($_) for (1 .. $buffer); | |
131 } | |
132 } | |
133 | |
134 ############################################################################### |