Mercurial > hg > nginx-tests
annotate stream_proxy_bind.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 |
---|---|
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Test for stream proxy_bind directive. |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 |
626
5f9dfe85a1f2
Tests: skipped proxy_bind tests on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
622
diff
changeset
|
25 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 plan(skip_all => '127.0.0.2 local address required') |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' ); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 my $t = Test::Nginx->new()->has(qw/http proxy stream/)->plan(1) |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 ->write_file_expand('nginx.conf', <<'EOF'); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 daemon off; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 events { |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
974
diff
changeset
|
40 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
974
diff
changeset
|
41 |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 listen 127.0.0.1:8081; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 proxy_bind 127.0.0.2; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 proxy_pass 127.0.0.1:8082; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 http { |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 %%TEST_GLOBALS_HTTP%% |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
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:8080; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 server_name localhost; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
57 proxy_pass http://127.0.0.1:8081; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
62 listen 127.0.0.1:8082; |
622
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 location / { |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 add_header X-IP $remote_addr; |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 } |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 EOF |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 $t->write_file('index.html', ''); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 $t->run(); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 ############################################################################### |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 like(http_get('/'), qr/X-IP: 127.0.0.2/, 'bind'); |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 |
b241c3c0119b
Tests: stream proxy_bind test.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 ############################################################################### |