Mercurial > hg > nginx-tests
annotate 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 | 766bcbb632ee |
children |
rev | line source |
---|---|
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Tests for http proxy_bind directive. |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
25 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 plan(skip_all => '127.0.0.2 local address required') |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' ); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 |
953
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
29 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(5) |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 ->write_file_expand('nginx.conf', <<'EOF'); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 daemon off; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 events { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 http { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
40 %%TEST_GLOBALS_HTTP%% |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
41 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
953
diff
changeset
|
43 listen 127.0.0.1:8080; |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 server_name localhost; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 proxy_bind 127.0.0.2; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 location / { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 proxy_bind 127.0.0.1; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
953
diff
changeset
|
50 proxy_pass http://127.0.0.1:8081/; |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 location /inherit { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
953
diff
changeset
|
54 proxy_pass http://127.0.0.1:8081/; |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 location /off { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 proxy_bind off; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
953
diff
changeset
|
59 proxy_pass http://127.0.0.1:8081/; |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 location /var { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 proxy_bind $arg_b; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
953
diff
changeset
|
64 proxy_pass http://127.0.0.1:8081/; |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 } |
953
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
66 |
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
67 location /port { |
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
68 proxy_bind 127.0.0.2:$remote_port; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
953
diff
changeset
|
69 proxy_pass http://127.0.0.1:8081/; |
953
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
70 add_header X-Client-Port $remote_port; |
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
71 } |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
953
diff
changeset
|
75 listen 127.0.0.1:8081; |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 server_name localhost; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 location / { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 add_header X-IP $remote_addr; |
953
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
80 add_header X-Port $remote_port; |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
82 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
83 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
84 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 EOF |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 $t->write_file('index.html', ''); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 $t->run(); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
90 ############################################################################### |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
91 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
92 like(http_get('/'), qr/X-IP: 127.0.0.1/, 'bind'); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
93 like(http_get('/inherit'), qr/X-IP: 127.0.0.2/, 'bind inherit'); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
94 like(http_get('/off'), qr/X-IP: 127.0.0.1/, 'bind off'); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
95 like(http_get('/var?b=127.0.0.2'), qr/X-IP: 127.0.0.2/, 'bind var'); |
953
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
96 like(http_get('/port'), qr/Port: (\d+)(?!\d).*Port: \1/s, 'bind port'); |
2bbab9bd73e5
Tests: added proxy_bind test with port.
Sergey Kandaurov <pluknet@nginx.com>
parents:
952
diff
changeset
|
97 |
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
98 ############################################################################### |