Mercurial > hg > nginx-tests
annotate proxy_cache_error.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 4f238efded81 |
children |
rev | line source |
---|---|
1266
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for http proxy cache, "header already sent" alerts on backend errors, |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 # http://mailman.nginx.org/pipermail/nginx-devel/2018-January/010737.html. |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 ############################################################################### |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use warnings; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 use strict; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 use Test::More; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use lib 'lib'; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 use Test::Nginx; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 ############################################################################### |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(1) |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 daemon off; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 events { |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 } |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 http { |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 proxy_cache_path %%TESTDIR%%/cache levels=1:2 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 keys_zone=NAME:1m; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 server { |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 listen 127.0.0.1:8080; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 server_name localhost; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 location / { |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 proxy_pass http://127.0.0.1:8081; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 proxy_cache NAME; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 |
1408
51656beb9996
Tests: adjusted proxy_cache_error.t read timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
49 proxy_read_timeout 500ms; |
1266
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 } |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 } |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 server { |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 listen 127.0.0.1:8081; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 server_name localhost; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 location / { |
1267
f94e79aad895
Tests: fixed proxy_cache_error.t with "tcp_nopush on".
Maxim Dounin <mdounin@mdounin.ru>
parents:
1266
diff
changeset
|
58 postpone_output 0; |
1266
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 limit_rate 512; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 expires 1m; |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 } |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 } |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 } |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 EOF |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 $t->write_file('big.html', 'x' x 1024); |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 $t->run(); |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 ############################################################################### |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 |
1408
51656beb9996
Tests: adjusted proxy_cache_error.t read timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
73 # make a HEAD request; since cache is enabled, nginx converts HEAD to GET |
1266
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 # and will set u->pipe->downstream_error to suppress sending the response |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 # body to the client |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 like(http_head('/big.html'), qr/200 OK/, 'head request'); |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 # once proxy_read_timeout expires, nginx will call |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 # ngx_http_finalize_upstream_request() with u->pipe->downstream_error set |
1772
4f238efded81
Tests: corrected proxy_cache_error.t comment.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1408
diff
changeset
|
81 # and rc = NGX_HTTP_BAD_GATEWAY; after revision ad3f342f14ba046c this |
4f238efded81
Tests: corrected proxy_cache_error.t comment.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1408
diff
changeset
|
82 # will result in ngx_http_finalize_request(NGX_HTTP_BAD_GATEWAY), |
1266
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 # leading to an attempt to return additional error response and |
1270
6f0e68970b94
Tests: adjusted todo in proxy_cache_error.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1269
diff
changeset
|
84 # the "header already sent" alert; fixed in 93abb5a855d6 |
1266
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 |
b17f27fa9081
Tests: tests for "header already sent" alerts on backend errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 ############################################################################### |