Mercurial > hg > nginx-tests
annotate proxy_cache_range.t @ 1021:ebdf239722b9
Tests: relaxed proxy_cache_lock.t nolock tests to fix on Solaris.
Assumed that the order of responses being arrived in nolock case may be ignored.
An important part of such case is that the only last response should be cached.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 02 Sep 2016 12:17:35 +0300 |
parents | 196d33c2bb45 |
children | 616e682e4ca5 |
rev | line source |
---|---|
371
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for http proxy cache and range filter. |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1008
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(7) |
371
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 ->write_file_expand('nginx.conf', <<'EOF'); |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 %%TEST_GLOBALS%% |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 daemon off; |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 events { |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 } |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 http { |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 %%TEST_GLOBALS_HTTP%% |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 proxy_cache_path %%TESTDIR%%/cache levels=1:2 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 keys_zone=NAME:1m; |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
41 listen 127.0.0.1:8080; |
371
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 server_name localhost; |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 proxy_pass http://127.0.0.1:8081; |
371
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 proxy_cache NAME; |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 proxy_cache_valid 200 1m; |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 } |
500
b4d657ba1a62
Tests: tests for range requests below proxy_cache_min_uses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
49 location /min_uses { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
50 proxy_pass http://127.0.0.1:8081/; |
500
b4d657ba1a62
Tests: tests for range requests below proxy_cache_min_uses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
51 proxy_cache NAME; |
b4d657ba1a62
Tests: tests for range requests below proxy_cache_min_uses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
52 proxy_cache_valid 200 1m; |
b4d657ba1a62
Tests: tests for range requests below proxy_cache_min_uses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
53 proxy_cache_min_uses 2; |
b4d657ba1a62
Tests: tests for range requests below proxy_cache_min_uses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
54 } |
371
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 } |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
58 listen 127.0.0.1:8081; |
371
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 server_name localhost; |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 location / { |
1008
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
62 if ($arg_s) { |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
63 limit_rate 50k; |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
64 } |
371
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 } |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 } |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 } |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 EOF |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 $t->write_file('t.html', 'SEE-THIS'); |
1008
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
72 |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
73 # should not fit in a single proxy buffer |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
74 |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
75 $t->write_file('tbig.html', |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
76 join('', map { sprintf "XX%06dXX", $_ } (1 .. 7000))); |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
77 |
371
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 $t->run(); |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 ############################################################################### |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 like(http_get_range('/t.html?1', 'Range: bytes=4-'), qr/^THIS/m, |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 'range on first request'); |
382
30364c578416
Tests: adjusted TODO for single range not-yet-cached requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
372
diff
changeset
|
84 |
30364c578416
Tests: adjusted TODO for single range not-yet-cached requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
372
diff
changeset
|
85 { |
30364c578416
Tests: adjusted TODO for single range not-yet-cached requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
372
diff
changeset
|
86 local $TODO = 'not yet'; |
30364c578416
Tests: adjusted TODO for single range not-yet-cached requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
372
diff
changeset
|
87 |
371
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 like(http_get_range('/t.html?2', 'Range: bytes=0-2,4-'), qr/^SEE.*^THIS/ms, |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 'multipart range on first request'); |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 } |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 like(http_get_range('/t.html?1', 'Range: bytes=4-'), qr/^THIS/m, |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 'cached range'); |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 like(http_get_range('/t.html?1', 'Range: bytes=0-2,4-'), qr/^SEE.*^THIS/ms, |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 'cached multipart range'); |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 |
500
b4d657ba1a62
Tests: tests for range requests below proxy_cache_min_uses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
97 like(http_get_range('/min_uses/t.html?3', 'Range: bytes=4-'), |
b4d657ba1a62
Tests: tests for range requests below proxy_cache_min_uses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
98 qr/^THIS/m, 'range below min_uses'); |
b4d657ba1a62
Tests: tests for range requests below proxy_cache_min_uses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
99 |
b4d657ba1a62
Tests: tests for range requests below proxy_cache_min_uses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
100 like(http_get_range('/min_uses/t.html?4', 'Range: bytes=0-2,4-'), |
b4d657ba1a62
Tests: tests for range requests below proxy_cache_min_uses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
101 qr/^SEE.*^THIS/ms, 'multipart range below min_uses'); |
b4d657ba1a62
Tests: tests for range requests below proxy_cache_min_uses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
102 |
1008
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
103 TODO: { |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
104 local $TODO = 'not yet' if $t->read_file('nginx.conf') =~ /sendfile on/ |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
105 and $t->read_file('nginx.conf') =~ /aio threads/ and $^O eq 'linux'; |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
106 |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
107 like(http_get_range('/tbig.html?s=1', 'Range: bytes=0-19'), |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
108 qr/^XX000001XXXX000002XX$/ms, 'range of response received in parts'); |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
109 |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
110 } |
bab7b53a156f
Tests: proxy cache range with sendfile in threads.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
111 |
371
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 ############################################################################### |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
113 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
114 sub http_get_range { |
372 | 115 my ($url, $extra) = @_; |
116 return http(<<EOF); | |
371
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
117 GET $url HTTP/1.1 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
118 Host: localhost |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
119 Connection: close |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
120 $extra |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
121 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
122 EOF |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
123 } |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
124 |
6fb6fea36560
Tests: proxy cache and range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
125 ############################################################################### |