annotate binary_upgrade.t @ 1961:fe6f22da53ec default tip

Tests: tests for usage of discarded body. The client_max_body_size limit should be ignored when the request body is already discarded. In HTTP/1.x, this is done by checking the r->discard_body flag when the body is being discarded, and because r->headers_in.content_length_n is 0 when it's already discarded. This, however, does not happen with HTTP/2 and HTTP/3, and therefore "error_page 413" does not work without relaxing the limit. Further, with proxy_pass, r->headers_in.content_length_n is used to determine length of the request body, and therefore is not correct if discarding of the request body isn't yet complete. While discarding the request body, r->headers_in.content_length_n contains the rest of the body to discard (or, in case of chunked request body, the rest of the current chunk to discard). Similarly, the $content_length variable uses r->headers_in.content_length if available, and also incorrect. The $content_length variable is used when proxying with fastcgi_pass, grpc_pass, and uwsgi_pass (scgi_pass uses the value calculated based on the actual request body buffers, and therefore works correctly).
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 27 Apr 2024 18:55:50 +0300
parents 5ac6efbe5552
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1254
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for binary upgrade.
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 plan(skip_all => 'can leave orphaned process group')
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 unless $ENV{TEST_NGINX_UNSAFE};
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
1573
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
28 my $t = Test::Nginx->new(qr/http unix/)->plan(4)
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
29 ->write_file_expand('nginx.conf', <<'EOF');
1254
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 %%TEST_GLOBALS%%
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 events {
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 }
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
1573
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
36 http {
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
37 %%TEST_GLOBALS_HTTP%%
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
38
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
39 server {
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
40 listen unix:%%TESTDIR%%/unix.sock;
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
41 server_name localhost;
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
42 }
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
43 }
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
44
1254
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 EOF
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46
1573
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
47 my $d = $t->testdir();
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
48
1254
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 $t->run();
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 ###############################################################################
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 my $pid = $t->read_file('nginx.pid');
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 ok($pid, 'master pid');
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 kill 'USR2', $pid;
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57
1332
fe60c3959069 Tests: adjusted binary_upgrade.t for instrumented binaries.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1288
diff changeset
58 for (1 .. 30) {
1573
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
59 last if -e "$d/nginx.pid" && -e "$d/nginx.pid.oldbin";
1254
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 select undef, undef, undef, 0.2
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 }
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 isnt($t->read_file('nginx.pid'), $pid, 'master pid changed');
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 kill 'QUIT', $pid;
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66
1573
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
67 for (1 .. 30) {
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
68 last if ! -e "$d/nginx.pid.oldbin";
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
69 select undef, undef, undef, 0.2
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
70 }
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
71
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
72 ok(-e "$d/unix.sock", 'unix socket exists on old master shutdown');
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
73
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
74 # unix socket on new master termination
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
75
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
76 $pid = $t->read_file('nginx.pid');
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
77
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
78 kill 'USR2', $pid;
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
79
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
80 for (1 .. 30) {
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
81 last if -e "$d/nginx.pid" && -e "$d/nginx.pid.oldbin";
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
82 select undef, undef, undef, 0.2
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
83 }
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
84
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
85 kill 'TERM', $t->read_file('nginx.pid');
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
86
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
87 for (1 .. 30) {
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
88 last if ! -e "$d/nginx.pid.oldbin";
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
89 select undef, undef, undef, 0.2
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
90 }
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
91
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
92 ok(-e "$d/unix.sock", 'unix socket exists on new master termination');
d7e83ce613c2 Tests: unix sockets removal tests on master process exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1332
diff changeset
93
1254
6fff42643fd7 Tests: binary upgrade.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 ###############################################################################