Mercurial > hg > nginx-tests
annotate realip_hostname.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 | 97c8280de681 |
children |
rev | line source |
---|---|
1176
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for nginx realip module, 'unix:' and hostname in set_real_ip_from. |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http realip proxy unix/); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 server { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 listen 127.0.0.1:8080; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 listen unix:%%TESTDIR%%/unix.sock; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 server_name localhost; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 location /1 { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 set_real_ip_from localhost; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 add_header X-IP $remote_addr; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 location /2 { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 set_real_ip_from unix:; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 add_header X-IP $remote_addr; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 location /unix { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 proxy_pass http://unix:%%TESTDIR%%/unix.sock:/; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 proxy_set_header X-Real-IP 192.0.2.1; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 location /ip { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 proxy_pass http://127.0.0.1:8080/; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 proxy_set_header X-Real-IP 192.0.2.1; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 EOF |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 $t->write_file('1', ''); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 $t->write_file('2', ''); |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1176
diff
changeset
|
70 $t->run(); |
1176
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 plan(skip_all => 'no 127.0.0.1 on host') |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 if http_get('/1') !~ /X-IP: 127.0.0.1/m; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 $t->plan(4); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 ############################################################################### |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 like(http_get('/unix/2'), qr/X-IP: 192.0.2.1/, 'realip unix'); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 unlike(http_get('/unix/1'), qr/X-IP: 192.0.2.1/, 'realip unix - no match'); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 like(http_get('/ip/1'), qr/X-IP: 192.0.2.1/, 'realip hostname'); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 unlike(http_get('/ip/2'), qr/X-IP: 192.0.2.1/, 'realip hostname - no match'); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 ############################################################################### |