Mercurial > hg > nginx-tests
annotate geo_binary.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 | 1fe8d33f75ad |
children |
rev | line source |
---|---|
1044
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for nginx geo module with binary base. |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 plan(skip_all => 'long configuration parsing') unless $ENV{TEST_NGINX_UNSAFE}; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http geo/); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 $t->write_file_expand('nginx.conf', <<'EOF'); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 http { |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 geo $geo_base_create { |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 ranges; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 include base.conf; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 } |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 geo $geo_base_include { |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 ranges; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 include base.conf; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 } |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server { |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 listen 127.0.0.1:8080; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 server_name localhost; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 location / { |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 add_header X-IP $remote_addr; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 add_header X-GBc $geo_base_create; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 add_header X-GBi $geo_base_include; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 } |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 } |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 } |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 EOF |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 $t->write_file('1', ''); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 $t->write_file('base.conf', join('', map { |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 "127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." . $_ % 256 . |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 "-127." . $_/256/256 % 256 . "." . $_/256 % 256 . "." .$_ % 256 . " " . |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 ($_ == 1 ? "loopback" : "range$_") . ";" } (0 .. 100000))); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 $t->run(); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 plan(skip_all => 'no 127.0.0.1 on host') |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 if http_get('/1') !~ /X-IP: 127.0.0.1/m; |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 $t->plan(2); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 ############################################################################### |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 my $r = http_get('/1'); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 like($r, qr/^X-GBc: loopback/m, 'geo binary base create'); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 like($r, qr/^X-GBi: loopback/m, 'geo binary base include'); |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 ############################################################################### |