Mercurial > hg > nginx-tests
annotate stream_udp_proxy.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) Nginx, Inc. | |
4 | |
5 # Tests for stream proxy module with datagrams. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 use Test::Nginx::Stream qw/ dgram /; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
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/stream udp/)->plan(5) |
868 | 26 ->write_file_expand('nginx.conf', <<'EOF'); |
27 | |
28 %%TEST_GLOBALS%% | |
29 | |
30 daemon off; | |
31 | |
32 events { | |
33 } | |
34 | |
35 stream { | |
36 proxy_timeout 1s; | |
37 | |
38 server { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
39 listen 127.0.0.1:%%PORT_8080_UDP%% udp; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
40 proxy_pass 127.0.0.1:%%PORT_8081_UDP%%; |
868 | 41 |
42 proxy_responses 0; | |
43 } | |
44 | |
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:%%PORT_8082_UDP%% udp; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
47 proxy_pass 127.0.0.1:%%PORT_8081_UDP%%; |
868 | 48 |
49 proxy_responses 2; | |
50 } | |
51 | |
52 server { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
53 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
|
54 proxy_pass 127.0.0.1:%%PORT_8081_UDP%%; |
868 | 55 } |
56 } | |
57 | |
58 EOF | |
59 | |
60 | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
61 $t->run_daemon(\&udp_daemon, port(8081), $t); |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
62 $t->run(); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
63 $t->waitforfile($t->testdir . '/' . port(8081)); |
868 | 64 |
65 ############################################################################### | |
66 | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
67 my $s = dgram('127.0.0.1:' . port(8080)); |
935
25a4b2fdd3fb
Tests: I/O timeout options introduced in Stream.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
868
diff
changeset
|
68 is($s->io('1', read => 1, read_timeout => 0.5), '', 'proxy responses 0'); |
868 | 69 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
70 $s = dgram('127.0.0.1:' . port(8082)); |
868 | 71 is($s->io('1'), '1', 'proxy responses 1'); |
72 is($s->io('2', read => 2), '12', 'proxy responses 2'); | |
935
25a4b2fdd3fb
Tests: I/O timeout options introduced in Stream.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
868
diff
changeset
|
73 is($s->io('3', read => 3, read_timeout => 0.5), '12', 'proxy responses 3'); |
868 | 74 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
75 $s = dgram('127.0.0.1:' . port(8083)); |
868 | 76 is($s->io('3', read => 3), '123', 'proxy responses default'); |
77 | |
78 ############################################################################### | |
79 | |
80 sub udp_daemon { | |
81 my ($port, $t) = @_; | |
82 | |
83 my $server = IO::Socket::INET->new( | |
84 Proto => 'udp', | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
85 LocalAddr => '127.0.0.1:' . port(8081), |
868 | 86 Reuse => 1, |
87 ) | |
88 or die "Can't create listening socket: $!\n"; | |
89 | |
90 # signal we are ready | |
91 | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
92 open my $fh, '>', $t->testdir() . '/' . port(8081); |
868 | 93 close $fh; |
94 | |
95 while (1) { | |
96 $server->recv(my $buffer, 65536); | |
97 $server->send($_) for (1 .. $buffer); | |
98 } | |
99 } | |
100 | |
101 ############################################################################### |