comparison stream_udp_limit_conn.t @ 1237:e4974af3fb12

Tests: adjusted udp ports to match allocated ports range.
author Andrey Zelenkov <zelenkov@nginx.com>
date Wed, 13 Sep 2017 19:04:25 +0300
parents 196d33c2bb45
children c4f58dfe8207
comparison
equal deleted inserted replaced
1236:93f749c1d5c5 1237:e4974af3fb12
39 39
40 proxy_responses 1; 40 proxy_responses 1;
41 proxy_timeout 1s; 41 proxy_timeout 1s;
42 42
43 server { 43 server {
44 listen 127.0.0.1:%%PORT_8081_UDP%% udp; 44 listen 127.0.0.1:%%PORT_8981_UDP%% udp;
45 proxy_pass 127.0.0.1:%%PORT_8080_UDP%%; 45 proxy_pass 127.0.0.1:%%PORT_8980_UDP%%;
46 46
47 limit_conn zone 1; 47 limit_conn zone 1;
48 proxy_responses 2; 48 proxy_responses 2;
49 } 49 }
50 50
51 server { 51 server {
52 listen 127.0.0.1:%%PORT_8082_UDP%% udp; 52 listen 127.0.0.1:%%PORT_8982_UDP%% udp;
53 proxy_pass 127.0.0.1:%%PORT_8080_UDP%%; 53 proxy_pass 127.0.0.1:%%PORT_8980_UDP%%;
54 limit_conn zone2 1; 54 limit_conn zone2 1;
55 } 55 }
56 56
57 server { 57 server {
58 listen 127.0.0.1:%%PORT_8083_UDP%% udp; 58 listen 127.0.0.1:%%PORT_8983_UDP%% udp;
59 proxy_pass 127.0.0.1:%%PORT_8080_UDP%%; 59 proxy_pass 127.0.0.1:%%PORT_8980_UDP%%;
60 limit_conn zone 5; 60 limit_conn zone 5;
61 } 61 }
62 62
63 server { 63 server {
64 listen 127.0.0.1:%%PORT_8084_UDP%% udp; 64 listen 127.0.0.1:%%PORT_8984_UDP%% udp;
65 proxy_pass 127.0.0.1:%%PORT_8081_UDP%%; 65 proxy_pass 127.0.0.1:%%PORT_8981_UDP%%;
66 limit_conn zone2 1; 66 limit_conn zone2 1;
67 } 67 }
68 68
69 server { 69 server {
70 listen 127.0.0.1:%%PORT_8085_UDP%% udp; 70 listen 127.0.0.1:%%PORT_8985_UDP%% udp;
71 proxy_pass 127.0.0.1:%%PORT_8081_UDP%%; 71 proxy_pass 127.0.0.1:%%PORT_8981_UDP%%;
72 limit_conn zone 1; 72 limit_conn zone 1;
73 } 73 }
74 } 74 }
75 75
76 EOF 76 EOF
77 77
78 $t->run(); 78 $t->run();
79 $t->run_daemon(\&udp_daemon, $t); 79 $t->run_daemon(\&udp_daemon, $t);
80 $t->waitforfile($t->testdir . '/' . port(8080)); 80 $t->waitforfile($t->testdir . '/' . port(8980));
81 81
82 ############################################################################### 82 ###############################################################################
83 83
84 # same and other zones 84 # same and other zones
85 85
86 my $s = dgram('127.0.0.1:' . port(8081)); 86 my $s = dgram('127.0.0.1:' . port(8981));
87 87
88 is($s->io('1'), '1', 'passed'); 88 is($s->io('1'), '1', 'passed');
89 89
90 # if not all responses were sent to client, then new request 90 # if not all responses were sent to client, then new request
91 # in same socket will be treated as new connection 91 # in same socket will be treated as new connection
92 92
93 is($s->io('1', read_timeout => 0.1), '', 'rejected new connection'); 93 is($s->io('1', read_timeout => 0.1), '', 'rejected new connection');
94 is(dgram('127.0.0.1:' . port(8081))->io('1', read_timeout => 0.1), '', 94 is(dgram('127.0.0.1:' . port(8981))->io('1', read_timeout => 0.1), '',
95 'rejected same zone'); 95 'rejected same zone');
96 is(dgram('127.0.0.1:' . port(8082))->io('1'), '1', 'passed different zone'); 96 is(dgram('127.0.0.1:' . port(8982))->io('1'), '1', 'passed different zone');
97 is(dgram('127.0.0.1:' . port(8083))->io('1'), '1', 'passed same zone unlimited'); 97 is(dgram('127.0.0.1:' . port(8983))->io('1'), '1', 'passed same zone unlimited');
98 98
99 sleep 1; # waiting for proxy_timeout to expire 99 sleep 1; # waiting for proxy_timeout to expire
100 100
101 is($s->io('2', read => 2), '12', 'new connection after proxy_timeout'); 101 is($s->io('2', read => 2), '12', 'new connection after proxy_timeout');
102 102
103 is(dgram('127.0.0.1:' . port(8081))->io('2', read => 2), '12', 'passed 2'); 103 is(dgram('127.0.0.1:' . port(8981))->io('2', read => 2), '12', 'passed 2');
104 104
105 # zones proxy chain 105 # zones proxy chain
106 106
107 is(dgram('127.0.0.1:' . port(8084))->io('1'), '1', 'passed proxy'); 107 is(dgram('127.0.0.1:' . port(8984))->io('1'), '1', 'passed proxy');
108 is(dgram('127.0.0.1:' . port(8085))->io('1', read_timeout => 0.1), '', 108 is(dgram('127.0.0.1:' . port(8985))->io('1', read_timeout => 0.1), '',
109 'rejected proxy'); 109 'rejected proxy');
110 110
111 ############################################################################### 111 ###############################################################################
112 112
113 sub udp_daemon { 113 sub udp_daemon {
114 my $t = shift; 114 my $t = shift;
115 115
116 my $server = IO::Socket::INET->new( 116 my $server = IO::Socket::INET->new(
117 Proto => 'udp', 117 Proto => 'udp',
118 LocalAddr => '127.0.0.1:' . port(8080), 118 LocalAddr => '127.0.0.1:' . port(8980),
119 Reuse => 1, 119 Reuse => 1,
120 ) 120 )
121 or die "Can't create listening socket: $!\n"; 121 or die "Can't create listening socket: $!\n";
122 122
123 # signal we are ready 123 # signal we are ready
124 124
125 open my $fh, '>', $t->testdir() . '/' . port(8080); 125 open my $fh, '>', $t->testdir() . '/' . port(8980);
126 close $fh; 126 close $fh;
127 127
128 while (1) { 128 while (1) {
129 $server->recv(my $buffer, 65536); 129 $server->recv(my $buffer, 65536);
130 $server->send($_) for (1 .. $buffer); 130 $server->send($_) for (1 .. $buffer);