Mercurial > hg > nginx-tests
annotate stream_udp_limit_conn.t @ 1752:ba6e24e38f03
Tests: improved stop_daemons() to send signal again.
As was observed, it's possible that a signal to complete a uwsgi daemon
can be ignored while it is starting up, which results in tests hang due
to eternal waiting on child processes termination. Notably, it is seen
when running tests with a high number of prove jobs on a low-profile VM
against nginx with broken modules and/or configuration. To reproduce:
$ TEST_NGINX_GLOBALS=ERROR prove -j16 uwsgi*.t
Inspecting uwsgi under ktrace on FreeBSD confirms that a SIGTERM signal
is ignored at the very beginning of uwsgi startup. It is then replaced
with a default action after listen(), thus waiting until uwsgi is ready
to accept new TCP connections doesn't completely solve the hang window.
The fix is to retry sending a signal some time after waitpid(WNOHANG)
continuously demonstrated no progress with reaping a signaled process.
It is modelled after f13ead27f89c that improved stop() for nginx.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 29 Dec 2021 22:29:23 +0300 |
parents | f3ba4c74de31 |
children |
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 { | |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1535
diff
changeset
|
37 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1535
diff
changeset
|
38 |
868 | 39 limit_conn_zone $binary_remote_addr zone=zone:1m; |
40 limit_conn_zone $binary_remote_addr zone=zone2:1m; | |
41 | |
42 proxy_responses 1; | |
43 proxy_timeout 1s; | |
44 | |
45 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
46 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
|
47 proxy_pass 127.0.0.1:%%PORT_8980_UDP%%; |
868 | 48 |
49 limit_conn zone 1; | |
50 proxy_responses 2; | |
51 } | |
52 | |
53 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
54 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
|
55 proxy_pass 127.0.0.1:%%PORT_8980_UDP%%; |
868 | 56 limit_conn zone2 1; |
57 } | |
58 | |
59 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
60 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
|
61 proxy_pass 127.0.0.1:%%PORT_8980_UDP%%; |
868 | 62 limit_conn zone 5; |
63 } | |
64 | |
65 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
66 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
|
67 proxy_pass 127.0.0.1:%%PORT_8981_UDP%%; |
868 | 68 limit_conn zone2 1; |
69 } | |
70 | |
71 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
72 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
|
73 proxy_pass 127.0.0.1:%%PORT_8981_UDP%%; |
868 | 74 limit_conn zone 1; |
75 } | |
76 } | |
77 | |
78 EOF | |
79 | |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
80 $t->run(); |
868 | 81 $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
|
82 $t->waitforfile($t->testdir . '/' . port(8980)); |
868 | 83 |
84 ############################################################################### | |
85 | |
86 # same and other zones | |
87 | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
88 my $s = dgram('127.0.0.1:' . port(8981)); |
868 | 89 |
90 is($s->io('1'), '1', 'passed'); | |
91 | |
1334
c4f58dfe8207
Tests: stream udp tests adjusted for upcoming udp streams.
Roman Arutyunyan <arut@nginx.com>
parents:
1237
diff
changeset
|
92 # regardless of incomplete responses, new requests in the same |
c4f58dfe8207
Tests: stream udp tests adjusted for upcoming udp streams.
Roman Arutyunyan <arut@nginx.com>
parents:
1237
diff
changeset
|
93 # socket will be treated as requests in existing session |
c4f58dfe8207
Tests: stream udp tests adjusted for upcoming udp streams.
Roman Arutyunyan <arut@nginx.com>
parents:
1237
diff
changeset
|
94 |
1349
99a83f7e7755
Tests: adjusted read timeout in stream_udp_limit_conn.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
95 is($s->io('1', read_timeout => 0.4), '1', 'passed new request'); |
1334
c4f58dfe8207
Tests: stream udp tests adjusted for upcoming udp streams.
Roman Arutyunyan <arut@nginx.com>
parents:
1237
diff
changeset
|
96 |
1237
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(8981))->io('1', read_timeout => 0.1), '', |
1334
c4f58dfe8207
Tests: stream udp tests adjusted for upcoming udp streams.
Roman Arutyunyan <arut@nginx.com>
parents:
1237
diff
changeset
|
98 'rejected new session'); |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
99 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
|
100 is(dgram('127.0.0.1:' . port(8983))->io('1'), '1', 'passed same zone unlimited'); |
868 | 101 |
935
25a4b2fdd3fb
Tests: I/O timeout options introduced in Stream.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
925
diff
changeset
|
102 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
|
103 |
1334
c4f58dfe8207
Tests: stream udp tests adjusted for upcoming udp streams.
Roman Arutyunyan <arut@nginx.com>
parents:
1237
diff
changeset
|
104 is($s->io('2', read => 2), '12', 'new session after proxy_timeout'); |
868 | 105 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
106 is(dgram('127.0.0.1:' . port(8981))->io('2', read => 2), '12', 'passed 2'); |
868 | 107 |
108 # zones proxy chain | |
109 | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
110 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
|
111 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
|
112 'rejected proxy'); |
868 | 113 |
114 ############################################################################### | |
115 | |
116 sub udp_daemon { | |
117 my $t = shift; | |
118 | |
119 my $server = IO::Socket::INET->new( | |
120 Proto => 'udp', | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
121 LocalAddr => '127.0.0.1:' . port(8980), |
868 | 122 Reuse => 1, |
123 ) | |
124 or die "Can't create listening socket: $!\n"; | |
125 | |
126 # signal we are ready | |
127 | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
128 open my $fh, '>', $t->testdir() . '/' . port(8980); |
868 | 129 close $fh; |
130 | |
131 while (1) { | |
132 $server->recv(my $buffer, 65536); | |
133 $server->send($_) for (1 .. $buffer); | |
134 } | |
135 } | |
136 | |
137 ############################################################################### |