Mercurial > hg > nginx-tests
annotate stream_udp_proxy.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 | 5ac6efbe5552 |
children |
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 | |
1574
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/stream udp/)->plan(8) |
868 | 26 ->write_file_expand('nginx.conf', <<'EOF'); |
27 | |
28 %%TEST_GLOBALS%% | |
29 | |
30 daemon off; | |
31 | |
32 events { | |
33 } | |
34 | |
35 stream { | |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1574
diff
changeset
|
36 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1574
diff
changeset
|
37 |
868 | 38 proxy_timeout 1s; |
39 | |
40 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
41 listen 127.0.0.1:%%PORT_8980_UDP%% udp; |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
42 proxy_pass 127.0.0.1:%%PORT_8981_UDP%%; |
868 | 43 |
44 proxy_responses 0; | |
45 } | |
46 | |
47 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
48 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
|
49 proxy_pass 127.0.0.1:%%PORT_8981_UDP%%; |
868 | 50 |
51 proxy_responses 2; | |
52 } | |
53 | |
54 server { | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
55 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
|
56 proxy_pass 127.0.0.1:%%PORT_8981_UDP%%; |
868 | 57 } |
58 } | |
59 | |
60 EOF | |
61 | |
62 | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
63 $t->run_daemon(\&udp_daemon, port(8981), $t); |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
64 $t->run(); |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
65 $t->waitforfile($t->testdir . '/' . port(8981)); |
868 | 66 |
67 ############################################################################### | |
68 | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
69 my $s = dgram('127.0.0.1:' . port(8980)); |
935
25a4b2fdd3fb
Tests: I/O timeout options introduced in Stream.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
868
diff
changeset
|
70 is($s->io('1', read => 1, read_timeout => 0.5), '', 'proxy responses 0'); |
868 | 71 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
72 $s = dgram('127.0.0.1:' . port(8982)); |
868 | 73 is($s->io('1'), '1', 'proxy responses 1'); |
1334
c4f58dfe8207
Tests: stream udp tests adjusted for upcoming udp streams.
Roman Arutyunyan <arut@nginx.com>
parents:
1237
diff
changeset
|
74 $s = dgram('127.0.0.1:' . port(8982)); |
868 | 75 is($s->io('2', read => 2), '12', 'proxy responses 2'); |
76 | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
77 $s = dgram('127.0.0.1:' . port(8983)); |
868 | 78 is($s->io('3', read => 3), '123', 'proxy responses default'); |
79 | |
1574
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
80 # zero-length payload |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
81 |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
82 $s = dgram('127.0.0.1:' . port(8982)); |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
83 $s->write(''); |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
84 is($s->read(), 'zero', 'upstream read zero bytes'); |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
85 is($s->read(), '', 'upstream sent zero bytes'); |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
86 |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
87 $s->write(''); |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
88 is($s->read(), 'zero', 'upstream read zero bytes again'); |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
89 is($s->read(), '', 'upstream sent zero bytes again'); |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
90 |
868 | 91 ############################################################################### |
92 | |
93 sub udp_daemon { | |
94 my ($port, $t) = @_; | |
95 | |
96 my $server = IO::Socket::INET->new( | |
97 Proto => 'udp', | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
98 LocalAddr => '127.0.0.1:' . port(8981), |
868 | 99 Reuse => 1, |
100 ) | |
101 or die "Can't create listening socket: $!\n"; | |
102 | |
103 # signal we are ready | |
104 | |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
105 open my $fh, '>', $t->testdir() . '/' . port(8981); |
868 | 106 close $fh; |
107 | |
108 while (1) { | |
109 $server->recv(my $buffer, 65536); | |
1574
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
110 |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
111 if (length($buffer) > 0) { |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
112 $server->send($_) for (1 .. $buffer); |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
113 |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
114 } else { |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
115 $server->send('zero'); |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
116 select undef, undef, undef, 0.2; |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
117 $server->send(''); |
42e37e0434d5
Tests: stream udp tests with zero-length payload (ticket #1982).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1334
diff
changeset
|
118 } |
868 | 119 } |
120 } | |
121 | |
122 ############################################################################### |