Mercurial > hg > nginx-tests
annotate proxy_cache_chunked.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 196d33c2bb45 |
children |
rev | line source |
---|---|
239
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Test for proxy cache with Transfer-Encoding: chunked. |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 use Socket qw/ CRLF /; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 use lib 'lib'; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 use Test::Nginx; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 ############################################################################### |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(2); |
239
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 $t->write_file_expand('nginx.conf', <<'EOF'); |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
241
diff
changeset
|
32 daemon off; |
239
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 events { |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 } |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 http { |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
503
071e8941e3bf
Tests: reduce shared memory zone sizes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
295
diff
changeset
|
40 proxy_cache_path %%TESTDIR%%/cache keys_zone=NAME:1m; |
239
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 listen 127.0.0.1:8080; |
239
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 server_name localhost; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
47 proxy_pass http://127.0.0.1:8081; |
239
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 proxy_http_version 1.1; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 proxy_cache NAME; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 proxy_cache_valid any 1m; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 add_header X-Status $upstream_cache_status; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 } |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 } |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 } |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 EOF |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 $t->run_daemon(\&http_chunked_daemon); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
59 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
239
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 ############################################################################### |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 like(http_get("/"), qr/SEE-THIS/s, "chunked"); |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 like(http_get("/"), qr/SEE-THIS.*HIT/s, "chunked cached"); |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 ############################################################################### |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 sub http_chunked_daemon { |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 my $server = IO::Socket::INET->new( |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
71 LocalAddr => '127.0.0.1:' . port(8081), |
239
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 Listen => 5, |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 Reuse => 1 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 ) |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 or die "Can't create listening socket: $!\n"; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 |
295
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
260
diff
changeset
|
77 local $SIG{PIPE} = 'IGNORE'; |
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
260
diff
changeset
|
78 |
239
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 while (my $client = $server->accept()) { |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 $client->autoflush(1); |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 while (<$client>) { |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 last if (/^\x0d?\x0a?$/); |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 } |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 print $client <<'EOF'; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 HTTP/1.1 200 OK |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 X-Test: SEE-THIS |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 Connection: close |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 Transfer-Encoding: chunked |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 EOF |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 print $client "85" . CRLF; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 select undef, undef, undef, 0.1; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 print $client "FOO" . ("0123456789abcdef" x 8) . CRLF . CRLF; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 print $client "0" . CRLF . CRLF; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 close $client; |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 } |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 } |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 |
5d178e27037c
Tests: test for proxy_cache with chunked response.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 ############################################################################### |