annotate stream_udp_upstream.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 e74a9342eb96
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
2
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
5
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
6 # Stream tests for upstream module and balancers with datagrams.
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
7
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
8 ###############################################################################
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
9
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
10 use warnings;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
11 use strict;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
12
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
13 use Test::More;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
14
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
16
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
17 use lib 'lib';
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
19 use Test::Nginx::Stream qw/ dgram /;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
20
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
21 ###############################################################################
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
22
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
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 udp/)->plan(4)
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
27 ->write_file_expand('nginx.conf', <<'EOF');
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
28
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
29 %%TEST_GLOBALS%%
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
30
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
31 daemon off;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
32
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
33 events {
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
34 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
35
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
36 stream {
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
37 proxy_responses 1;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
38 proxy_timeout 1s;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
39
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
40 upstream u {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
41 server 127.0.0.1:%%PORT_8084_UDP%%;
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
42 server 127.0.0.1:%%PORT_8085_UDP%%;
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
43 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
44
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
45 upstream u2 {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
46 server 127.0.0.1:%%PORT_8086_UDP%% down;
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
47 server 127.0.0.1:%%PORT_8086_UDP%%;
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
48 server 127.0.0.1:%%PORT_8084_UDP%%;
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
49 server 127.0.0.1:%%PORT_8085_UDP%%;
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
50 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
51
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
52 upstream u3 {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
53 server 127.0.0.1:%%PORT_8084_UDP%%;
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
54 server 127.0.0.1:%%PORT_8085_UDP%% weight=2;
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
55 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
56
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
57 upstream u4 {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
58 server 127.0.0.1:%%PORT_8086_UDP%%;
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
59 server 127.0.0.1:%%PORT_8084_UDP%% backup;
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
60 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
61
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
62 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
63 listen 127.0.0.1:%%PORT_8080_UDP%% udp;
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
64 proxy_pass u;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
65 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
66
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
67 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
68 listen 127.0.0.1:%%PORT_8081_UDP%% udp;
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
69 proxy_pass u2;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
70 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
71
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
72 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
73 listen 127.0.0.1:%%PORT_8082_UDP%% udp;
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
74 proxy_pass u3;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
75 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
76
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
77 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
78 listen 127.0.0.1:%%PORT_8083_UDP%% udp;
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
79 proxy_pass u4;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
80 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
81 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
82
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
83 EOF
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
84
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
85 $t->run_daemon(\&udp_daemon, port(8084), $t);
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
86 $t->run_daemon(\&udp_daemon, port(8085), $t);
1020
196d33c2bb45 Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 974
diff changeset
87 $t->run();
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
88
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
89 $t->waitforfile($t->testdir . '/' . port(8084));
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
90 $t->waitforfile($t->testdir . '/' . port(8085));
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
91
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
92 ###############################################################################
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
93
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
94 my @ports = my ($port4, $port5) = (port(8084), port(8085));
952
e9064d691790 Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
95
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
96 is(many(30, port(8080)), "$port4: 15, $port5: 15", 'balanced');
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
97 is(many(30, port(8081)), "$port4: 15, $port5: 15", 'failures');
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
98 is(many(30, port(8082)), "$port4: 10, $port5: 20", 'weight');
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
99 is(many(30, port(8083)), "$port4: 30", 'backup');
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
100
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
101 ###############################################################################
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
102
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
103 sub many {
952
e9064d691790 Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
104 my ($count, $port) = @_;
e9064d691790 Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
105 my (%ports);
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
106
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
107 for (1 .. $count) {
952
e9064d691790 Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
108 if (dgram("127.0.0.1:$port")->io('.') =~ /(\d+)/) {
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
109 $ports{$1} = 0 unless defined $ports{$1};
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
110 $ports{$1}++;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
111 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
112 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
113
952
e9064d691790 Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
114 my @keys = map { my $p = $_; grep { $p == $_ } keys %ports } @ports;
e9064d691790 Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
115 return join ', ', map { $_ . ": " . $ports{$_} } @keys;
868
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
116 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
117
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
118 ###############################################################################
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
119
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
120 sub udp_daemon {
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
121 my ($port, $t) = @_;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
122
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
123 my $server = IO::Socket::INET->new(
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
124 Proto => 'udp',
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
125 LocalAddr => '127.0.0.1:' . $port,
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
126 Reuse => 1,
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
127 )
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
128 or die "Can't create listening socket: $!\n";
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
129
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
130 # signal we are ready
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
131
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
132 open my $fh, '>', $t->testdir() . '/' . $port;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
133 close $fh;
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
134
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
135 while (1) {
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
136 $server->recv(my $buffer, 65536);
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
137 $buffer = $server->sockport();
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
138 $server->send($buffer);
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
139 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
140 }
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
141
d2cb9ed7412e Tests: stream udp tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
142 ###############################################################################