Mercurial > hg > nginx-tests
annotate proxy_store.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 882267679006 |
children |
rev | line source |
---|---|
46
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for proxy_store functionality. |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
121
8ac1faaddd2c
Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents:
107
diff
changeset
|
12 use Test::More; |
46
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 my $t = Test::Nginx->new(); |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
687
89cfb7397ba1
Tests: added proxy_store tests with variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
306
diff
changeset
|
26 $t->write_file_expand('nginx.conf', <<'EOF')->has(qw/http proxy ssi/)->plan(9); |
46
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
90
diff
changeset
|
28 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
90
diff
changeset
|
29 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
236
diff
changeset
|
30 daemon off; |
46
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 events { |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 } |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 http { |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
90
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
46
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
39 listen 127.0.0.1:8080; |
46
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 server_name localhost; |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 |
89
abbe4b123795
Tests: simplify proxy-store tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
88
diff
changeset
|
42 location /store- { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 proxy_pass http://127.0.0.1:8080/; |
87
f2d09159a8f3
Tests: proxy_store leaving temporary files bug test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
44 proxy_store on; |
f2d09159a8f3
Tests: proxy_store leaving temporary files bug test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
45 } |
687
89cfb7397ba1
Tests: added proxy_store tests with variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
306
diff
changeset
|
46 location /store-string- { |
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:8080/; |
687
89cfb7397ba1
Tests: added proxy_store tests with variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
306
diff
changeset
|
48 proxy_store %%TESTDIR%%$uri; |
89cfb7397ba1
Tests: added proxy_store tests with variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
306
diff
changeset
|
49 } |
90
1d3c82227a05
Tests: subrequests with proxy_store todo test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
89
diff
changeset
|
50 location /ssi.html { |
1d3c82227a05
Tests: subrequests with proxy_store todo test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
89
diff
changeset
|
51 ssi on; |
1d3c82227a05
Tests: subrequests with proxy_store todo test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
89
diff
changeset
|
52 } |
87
f2d09159a8f3
Tests: proxy_store leaving temporary files bug test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
53 location /index-big.html { |
f2d09159a8f3
Tests: proxy_store leaving temporary files bug test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
54 limit_rate 200k; |
f2d09159a8f3
Tests: proxy_store leaving temporary files bug test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
55 } |
46
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 } |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 } |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 EOF |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 $t->write_file('index.html', 'SEE-THIS'); |
47
bb6d65d833cd
Tests: test for X-Accel-Expires switching off proxy_store.
Maxim Dounin <mdounin@mdounin.ru>
parents:
46
diff
changeset
|
62 $t->write_file('index-nostore.html', 'SEE-THIS'); |
87
f2d09159a8f3
Tests: proxy_store leaving temporary files bug test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
63 $t->write_file('index-big.html', 'x' x (100 << 10)); |
90
1d3c82227a05
Tests: subrequests with proxy_store todo test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
89
diff
changeset
|
64 $t->write_file('ssi.html', |
1d3c82227a05
Tests: subrequests with proxy_store todo test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
89
diff
changeset
|
65 '<!--#include virtual="/store-index-big.html?1" -->' . |
1d3c82227a05
Tests: subrequests with proxy_store todo test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
89
diff
changeset
|
66 '<!--#include virtual="/store-index-big.html?2" -->' |
1d3c82227a05
Tests: subrequests with proxy_store todo test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
89
diff
changeset
|
67 ); |
46
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 $t->run(); |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 ############################################################################### |
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 |
89
abbe4b123795
Tests: simplify proxy-store tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
88
diff
changeset
|
72 like(http_get('/store-index.html'), qr/SEE-THIS/, 'proxy request'); |
abbe4b123795
Tests: simplify proxy-store tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
88
diff
changeset
|
73 ok(-e $t->testdir() . '/store-index.html', 'result stored'); |
46
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 |
687
89cfb7397ba1
Tests: added proxy_store tests with variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
306
diff
changeset
|
75 like(http_get('/store-string-index.html'), qr/SEE-THIS/, |
89cfb7397ba1
Tests: added proxy_store tests with variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
306
diff
changeset
|
76 'proxy string path request'); |
89cfb7397ba1
Tests: added proxy_store tests with variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
306
diff
changeset
|
77 ok(-e $t->testdir() . '/store-string-index.html', 'string path result stored'); |
89cfb7397ba1
Tests: added proxy_store tests with variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
306
diff
changeset
|
78 |
306
f175dc25f249
Tests: proxy_store with HEAD requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
79 like(http_head('/store-index-nostore.html'), qr/200 OK/, 'head request'); |
89
abbe4b123795
Tests: simplify proxy-store tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
88
diff
changeset
|
80 ok(!-e $t->testdir() . '/store-index-nostore.html', 'result not stored'); |
47
bb6d65d833cd
Tests: test for X-Accel-Expires switching off proxy_store.
Maxim Dounin <mdounin@mdounin.ru>
parents:
46
diff
changeset
|
81 |
bb6d65d833cd
Tests: test for X-Accel-Expires switching off proxy_store.
Maxim Dounin <mdounin@mdounin.ru>
parents:
46
diff
changeset
|
82 ok(scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]} == 0, 'no temp files'); |
bb6d65d833cd
Tests: test for X-Accel-Expires switching off proxy_store.
Maxim Dounin <mdounin@mdounin.ru>
parents:
46
diff
changeset
|
83 |
89
abbe4b123795
Tests: simplify proxy-store tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
88
diff
changeset
|
84 http_get('/store-index-big.html', aborted => 1, sleep => 0.1); |
236
5ac875a3088e
Tests: improve proxy_store.t timeouts a bit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
233
diff
changeset
|
85 |
233
1a5574d84917
Tests: tweak various timeouts and replace sleep() with select().
Maxim Dounin <mdounin@mdounin.ru>
parents:
224
diff
changeset
|
86 select(undef, undef, undef, 0.5); |
236
5ac875a3088e
Tests: improve proxy_store.t timeouts a bit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
233
diff
changeset
|
87 select(undef, undef, undef, 2.5) |
5ac875a3088e
Tests: improve proxy_store.t timeouts a bit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
233
diff
changeset
|
88 if scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]}; |
87
f2d09159a8f3
Tests: proxy_store leaving temporary files bug test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
89 |
f2d09159a8f3
Tests: proxy_store leaving temporary files bug test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
90 ok(scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]} == 0, |
f2d09159a8f3
Tests: proxy_store leaving temporary files bug test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
91 'no temp files after aborted request'); |
f2d09159a8f3
Tests: proxy_store leaving temporary files bug test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
92 |
90
1d3c82227a05
Tests: subrequests with proxy_store todo test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
89
diff
changeset
|
93 http_get('/ssi.html', aborted => 1, sleep => 0.1); |
236
5ac875a3088e
Tests: improve proxy_store.t timeouts a bit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
233
diff
changeset
|
94 |
233
1a5574d84917
Tests: tweak various timeouts and replace sleep() with select().
Maxim Dounin <mdounin@mdounin.ru>
parents:
224
diff
changeset
|
95 select(undef, undef, undef, 0.5); |
236
5ac875a3088e
Tests: improve proxy_store.t timeouts a bit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
233
diff
changeset
|
96 select(undef, undef, undef, 2.5) |
5ac875a3088e
Tests: improve proxy_store.t timeouts a bit.
Maxim Dounin <mdounin@mdounin.ru>
parents:
233
diff
changeset
|
97 if scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]}; |
90
1d3c82227a05
Tests: subrequests with proxy_store todo test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
89
diff
changeset
|
98 |
1d3c82227a05
Tests: subrequests with proxy_store todo test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
89
diff
changeset
|
99 ok(scalar @{[ glob $t->testdir() . '/proxy_temp/*' ]} == 0, |
1d3c82227a05
Tests: subrequests with proxy_store todo test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
89
diff
changeset
|
100 'no temp files after aborted ssi'); |
1d3c82227a05
Tests: subrequests with proxy_store todo test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
89
diff
changeset
|
101 |
46
239a346b4913
Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 ############################################################################### |