comparison access_log.t @ 1189:1c703303feee

Tests: basic open_log_file_cache log module tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 15 Jun 2017 19:20:47 +0300
parents 074e05b33b1a
children a9187b424a94
comparison
equal deleted inserted replaced
1188:074e05b33b1a 1189:1c703303feee
19 ############################################################################### 19 ###############################################################################
20 20
21 select STDERR; $| = 1; 21 select STDERR; $| = 1;
22 select STDOUT; $| = 1; 22 select STDOUT; $| = 1;
23 23
24 my $t = Test::Nginx->new()->has(qw/http rewrite gzip/)->plan(11) 24 my $t = Test::Nginx->new()->has(qw/http rewrite gzip/)->plan(15)
25 ->write_file_expand('nginx.conf', <<'EOF'); 25 ->write_file_expand('nginx.conf', <<'EOF');
26 26
27 %%TEST_GLOBALS%% 27 %%TEST_GLOBALS%%
28 28
29 daemon off; 29 daemon off;
88 location /varlog { 88 location /varlog {
89 access_log %%TESTDIR%%/varlog_${arg_logname} test; 89 access_log %%TESTDIR%%/varlog_${arg_logname} test;
90 return 200 OK; 90 return 200 OK;
91 } 91 }
92 92
93 location /cache {
94 open_log_file_cache max=3 inactive=20s valid=1m min_uses=2;
95 access_log %%TESTDIR%%/dir/cache_${arg_logname} test;
96 return 200 OK;
97 }
98
93 location /binary { 99 location /binary {
94 access_log %%TESTDIR%%/binary.log binary; 100 access_log %%TESTDIR%%/binary.log binary;
95 } 101 }
96 } 102 }
97 } 103 }
98 104
99 EOF 105 EOF
100 106
107 mkdir $t->testdir() . '/dir';
101 $t->run(); 108 $t->run();
102 109
103 ############################################################################### 110 ###############################################################################
104 111
105 http_get('/combined'); 112 http_get('/combined');
134 http_get('/varlog?logname=0'); 141 http_get('/varlog?logname=0');
135 http_get('/varlog?logname=filename'); 142 http_get('/varlog?logname=filename');
136 143
137 http_get('/binary'); 144 http_get('/binary');
138 145
146 http_get('/cache?logname=lru');
147 http_get('/cache?logname=lru');
148 http_get('/cache?logname=once');
149 http_get('/cache?logname=first');
150 http_get('/cache?logname=first');
151 http_get('/cache?logname=second');
152 http_get('/cache?logname=second');
153
154 chmod 0000, $t->testdir() . '/dir';
155
156 http_get('/cache?logname=lru');
157 http_get('/cache?logname=once');
158 http_get('/cache?logname=first');
159 http_get('/cache?logname=second');
160
139 # wait for file to appear with nonzero size thanks to the flush parameter 161 # wait for file to appear with nonzero size thanks to the flush parameter
140 162
141 for (1 .. 10) { 163 for (1 .. 10) {
142 last if -s $t->testdir() . '/compressed.log'; 164 last if -s $t->testdir() . '/compressed.log';
143 select undef, undef, undef, 0.1; 165 select undef, undef, undef, 0.1;
214 236
215 my $expected = join '', map { sprintf "\\x%02X", $_ } split /\./, $addr; 237 my $expected = join '', map { sprintf "\\x%02X", $_ } split /\./, $addr;
216 238
217 is($t->read_file('binary.log'), "$expected\n", 'binary'); 239 is($t->read_file('binary.log'), "$expected\n", 'binary');
218 240
219 ############################################################################### 241 chmod 0755, $t->testdir() . '/dir';
242
243 SKIP: {
244 skip 'win32', 4 if $^O eq 'MSWin32';
245
246 is(@{[$t->read_file('/dir/cache_lru') =~ /\//g]}, 2, 'cache - closed lru');
247 is(@{[$t->read_file('/dir/cache_once') =~ /\//g]}, 1, 'cache - min_uses');
248 is(@{[$t->read_file('/dir/cache_first') =~ /\//g]}, 3, 'cache - cached 1');
249 is(@{[$t->read_file('/dir/cache_second') =~ /\//g]}, 3, 'cache - cached 2');
250
251 }
252
253 ###############################################################################