Mercurial > hg > nginx-tests
annotate proxy_cache_manager.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 766bcbb632ee |
children |
rev | line source |
---|---|
1048
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for http proxy cache, manager parameters. |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 plan(skip_all => 'long test') unless $ENV{TEST_NGINX_UNSAFE}; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
1112
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
27 plan(skip_all => 'page size is not appropriate') unless |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
28 POSIX::sysconf(&POSIX::_SC_PAGESIZE) == 4096; |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
29 |
1048
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 my $t = Test::Nginx->new()->has(qw/http proxy cache/) |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 ->write_file_expand('nginx.conf', <<'EOF'); |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 %%TEST_GLOBALS%% |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 daemon off; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 events { |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 } |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 http { |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 %%TEST_GLOBALS_HTTP%% |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 proxy_cache_path %%TESTDIR%%/cache max_size=0 keys_zone=NAME:1m |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 manager_sleep=5 manager_files=2 manager_threshold=10; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
1112
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
46 proxy_cache_path %%TESTDIR%%/water keys_zone=NAM2:16k |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
47 manager_sleep=5; |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
48 |
1048
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 server { |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 listen 127.0.0.1:8080; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server_name localhost; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 location / { |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 proxy_pass http://127.0.0.1:8081; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 proxy_cache NAME; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 proxy_cache_valid any 1m; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 } |
1112
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
59 |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
60 location /water/ { |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
61 proxy_pass http://127.0.0.1:8081/t.html; |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
62 proxy_cache NAM2; |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
63 |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
64 proxy_cache_valid any 1m; |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
65 } |
1048
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 } |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 server { |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 listen 127.0.0.1:8081; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 server_name localhost; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 location / { } |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 } |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 } |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 EOF |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 $t->write_file('t.html', 'SEE-THIS'); |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1112
diff
changeset
|
79 $t->run()->plan(3); |
1048
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 ############################################################################### |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
1112
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
83 my $d = $t->testdir(); |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
84 |
1049
c65e5c0e2980
Tests: fixed startup race in proxy_cache_manager.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1048
diff
changeset
|
85 # wait for cache manager start |
c65e5c0e2980
Tests: fixed startup race in proxy_cache_manager.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1048
diff
changeset
|
86 |
c65e5c0e2980
Tests: fixed startup race in proxy_cache_manager.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1048
diff
changeset
|
87 sleep 1; |
c65e5c0e2980
Tests: fixed startup race in proxy_cache_manager.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1048
diff
changeset
|
88 |
1048
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 http_get("/t.html?$_") for (1 .. 5); |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
1112
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
91 # pretend we could not fit into zone |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
92 |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
93 http_get("/water/?$_") for (1 .. 100); |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
94 |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
95 my $n = files("$d/water"); |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
96 |
1052 | 97 # wait for cache manager process |
1048
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 |
1049
c65e5c0e2980
Tests: fixed startup race in proxy_cache_manager.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1048
diff
changeset
|
99 sleep 10; |
1048
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
1112
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
101 cmp_ok(files("$d/water"), '<', $n, 'manager watermark'); |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
102 |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
103 is(files("$d/cache"), 3, 'manager files'); |
1048
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 sleep 5; |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 |
1112
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
107 is(files("$d/cache"), 1, 'manager sleep'); |
1048
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 |
f38301fd4792
Tests: basic proxy cache manager tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 ############################################################################### |
1112
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
110 |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
111 sub files { |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
112 my ($path) = @_; |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
113 my $dh; |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
114 |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
115 opendir($dh, $path); |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
116 return scalar grep { ! /^\./ } readdir($dh); |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
117 } |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
118 |
79f93c764353
Tests: added basic proxy cache manager watermark test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1052
diff
changeset
|
119 ############################################################################### |