annotate http_uri.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 e4e711d07e6c
children 2a0a6035a1af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1515
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for URI normalization.
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
1714
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(19)
1515
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 ->write_file_expand('nginx.conf', <<'EOF')->run();
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 %%TEST_GLOBALS%%
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 daemon off;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 events {
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 }
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 http {
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 %%TEST_GLOBALS_HTTP%%
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 server {
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 listen 127.0.0.1:8080;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 server_name localhost;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 location / {
1635
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
43 add_header X-URI "x $uri x";
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
44 add_header X-Args "y $args y";
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
45 add_header X-Request-URI "z $request_uri z";
1515
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 return 204;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 }
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 }
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 }
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 EOF
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 ###############################################################################
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 like(http_get('/foo/bar%'), qr/400 Bad/, 'percent');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 like(http_get('/foo/bar%1'), qr/400 Bad/, 'percent digit');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 like(http_get('/foo/bar/.?args'), qr!x /foo/bar/ x!, 'dot args');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 like(http_get('/foo/bar/.#frag'), qr!x /foo/bar/ x!, 'dot frag');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 like(http_get('/foo/bar/..?args'), qr!x /foo/ x!, 'dot dot args');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 like(http_get('/foo/bar/..#frag'), qr!x /foo/ x!, 'dot dot frag');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 like(http_get('/foo/bar/.'), qr!x /foo/bar/ x!, 'trailing dot');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 like(http_get('/foo/bar/..'), qr!x /foo/ x!, 'trailing dot dot');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
1635
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
65 like(http_get('http://localhost'), qr!x / x!, 'absolute');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
66 like(http_get('http://localhost/'), qr!x / x!, 'absolute slash');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
67 like(http_get('http://localhost?args'), qr!x / x.*y args y!ms,
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
68 'absolute args');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
69 like(http_get('http://localhost?args#frag'), qr!x / x.*y args y!ms,
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
70 'absolute args and frag');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
71
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
72 like(http_get('http://localhost:8080'), qr!x / x!, 'port');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
73 like(http_get('http://localhost:8080/'), qr!x / x!, 'port slash');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
74 like(http_get('http://localhost:8080?args'), qr!x / x.*y args y!ms,
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
75 'port args');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
76 like(http_get('http://localhost:8080?args#frag'), qr!x / x.*y args y!ms,
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
77 'port args and frag');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
78
1706
9c79f41fdf9b Tests: updated test for spaces in URI to expect HTTP 400.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1693
diff changeset
79 TODO: {
1709
9fac05e479fa Tests: http_uri.t TODO adjusted.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1706
diff changeset
80 local $TODO = 'not yet' unless $t->has_version('1.21.1');
1706
9c79f41fdf9b Tests: updated test for spaces in URI to expect HTTP 400.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1693
diff changeset
81
9c79f41fdf9b Tests: updated test for spaces in URI to expect HTTP 400.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1693
diff changeset
82 like(http_get('/ /'), qr/400 Bad/, 'space');
9c79f41fdf9b Tests: updated test for spaces in URI to expect HTTP 400.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1693
diff changeset
83
9c79f41fdf9b Tests: updated test for spaces in URI to expect HTTP 400.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1693
diff changeset
84 }
1635
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
85
1714
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
86 TODO: {
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
87 local $TODO = 'not yet' unless $t->has_version('1.21.1');
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
88
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
89 like(http_get("/\x02"), qr/400 Bad/, 'control');
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
90
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
91 }
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
92
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
93 like(http_get('/%02'), qr!x /\x02 x!, 'control escaped');
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
94
1515
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 ###############################################################################