comparison proxy_cache_manager.t @ 1112:79f93c764353

Tests: added basic proxy cache manager watermark test.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 17 Jan 2017 17:47:55 +0300
parents 7cf9b3e849d2
children 766bcbb632ee
comparison
equal deleted inserted replaced
1111:6c2538ad642d 1112:79f93c764353
22 select STDERR; $| = 1; 22 select STDERR; $| = 1;
23 select STDOUT; $| = 1; 23 select STDOUT; $| = 1;
24 24
25 plan(skip_all => 'long test') unless $ENV{TEST_NGINX_UNSAFE}; 25 plan(skip_all => 'long test') unless $ENV{TEST_NGINX_UNSAFE};
26 26
27 plan(skip_all => 'page size is not appropriate') unless
28 POSIX::sysconf(&POSIX::_SC_PAGESIZE) == 4096;
29
27 my $t = Test::Nginx->new()->has(qw/http proxy cache/) 30 my $t = Test::Nginx->new()->has(qw/http proxy cache/)
28 ->write_file_expand('nginx.conf', <<'EOF'); 31 ->write_file_expand('nginx.conf', <<'EOF');
29 32
30 %%TEST_GLOBALS%% 33 %%TEST_GLOBALS%%
31 34
38 %%TEST_GLOBALS_HTTP%% 41 %%TEST_GLOBALS_HTTP%%
39 42
40 proxy_cache_path %%TESTDIR%%/cache max_size=0 keys_zone=NAME:1m 43 proxy_cache_path %%TESTDIR%%/cache max_size=0 keys_zone=NAME:1m
41 manager_sleep=5 manager_files=2 manager_threshold=10; 44 manager_sleep=5 manager_files=2 manager_threshold=10;
42 45
46 proxy_cache_path %%TESTDIR%%/water keys_zone=NAM2:16k
47 manager_sleep=5;
48
43 server { 49 server {
44 listen 127.0.0.1:8080; 50 listen 127.0.0.1:8080;
45 server_name localhost; 51 server_name localhost;
46 52
47 location / { 53 location / {
48 proxy_pass http://127.0.0.1:8081; 54 proxy_pass http://127.0.0.1:8081;
49 proxy_cache NAME; 55 proxy_cache NAME;
56
57 proxy_cache_valid any 1m;
58 }
59
60 location /water/ {
61 proxy_pass http://127.0.0.1:8081/t.html;
62 proxy_cache NAM2;
50 63
51 proxy_cache_valid any 1m; 64 proxy_cache_valid any 1m;
52 } 65 }
53 } 66 }
54 67
61 } 74 }
62 75
63 EOF 76 EOF
64 77
65 $t->write_file('t.html', 'SEE-THIS'); 78 $t->write_file('t.html', 'SEE-THIS');
66 $t->try_run('no manager params')->plan(2); 79 $t->try_run('no manager params')->plan(3);
67 80
68 ############################################################################### 81 ###############################################################################
82
83 my $d = $t->testdir();
69 84
70 # wait for cache manager start 85 # wait for cache manager start
71 86
72 sleep 1; 87 sleep 1;
73 88
74 http_get("/t.html?$_") for (1 .. 5); 89 http_get("/t.html?$_") for (1 .. 5);
75 90
91 # pretend we could not fit into zone
92
93 http_get("/water/?$_") for (1 .. 100);
94
95 my $n = files("$d/water");
96
76 # wait for cache manager process 97 # wait for cache manager process
77 98
78 sleep 10; 99 sleep 10;
79 100
80 opendir(my $dh, $t->testdir() . '/cache'); 101 cmp_ok(files("$d/water"), '<', $n, 'manager watermark');
81 my $files = grep { ! /^\./ } readdir($dh); 102
82 is($files, 3, 'manager files'); 103 is(files("$d/cache"), 3, 'manager files');
83 104
84 sleep 5; 105 sleep 5;
85 106
86 opendir($dh, $t->testdir() . '/cache'); 107 is(files("$d/cache"), 1, 'manager sleep');
87 $files = grep { ! /^\./ } readdir($dh);
88 is($files, 1, 'manager sleep');
89 108
90 ############################################################################### 109 ###############################################################################
110
111 sub files {
112 my ($path) = @_;
113 my $dh;
114
115 opendir($dh, $path);
116 return scalar grep { ! /^\./ } readdir($dh);
117 }
118
119 ###############################################################################