changeset 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 fcd65708672d
files access_log.t
diffstat 1 files changed, 35 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/access_log.t
+++ b/access_log.t
@@ -21,7 +21,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-my $t = Test::Nginx->new()->has(qw/http rewrite gzip/)->plan(11)
+my $t = Test::Nginx->new()->has(qw/http rewrite gzip/)->plan(15)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
@@ -90,6 +90,12 @@ http {
             return 200 OK;
         }
 
+        location /cache {
+            open_log_file_cache max=3 inactive=20s valid=1m min_uses=2;
+            access_log %%TESTDIR%%/dir/cache_${arg_logname} test;
+            return 200 OK;
+        }
+
         location /binary {
             access_log %%TESTDIR%%/binary.log binary;
         }
@@ -98,6 +104,7 @@ http {
 
 EOF
 
+mkdir $t->testdir() . '/dir';
 $t->run();
 
 ###############################################################################
@@ -136,6 +143,21 @@ http_get('/varlog?logname=filename');
 
 http_get('/binary');
 
+http_get('/cache?logname=lru');
+http_get('/cache?logname=lru');
+http_get('/cache?logname=once');
+http_get('/cache?logname=first');
+http_get('/cache?logname=first');
+http_get('/cache?logname=second');
+http_get('/cache?logname=second');
+
+chmod 0000, $t->testdir() . '/dir';
+
+http_get('/cache?logname=lru');
+http_get('/cache?logname=once');
+http_get('/cache?logname=first');
+http_get('/cache?logname=second');
+
 # wait for file to appear with nonzero size thanks to the flush parameter
 
 for (1 .. 10) {
@@ -216,4 +238,16 @@ my $expected = join '', map { sprintf "\
 
 is($t->read_file('binary.log'), "$expected\n", 'binary');
 
+chmod 0755, $t->testdir() . '/dir';
+
+SKIP: {
+skip 'win32', 4 if $^O eq 'MSWin32';
+
+is(@{[$t->read_file('/dir/cache_lru') =~ /\//g]}, 2, 'cache - closed lru');
+is(@{[$t->read_file('/dir/cache_once') =~ /\//g]}, 1, 'cache - min_uses');
+is(@{[$t->read_file('/dir/cache_first') =~ /\//g]}, 3, 'cache - cached 1');
+is(@{[$t->read_file('/dir/cache_second') =~ /\//g]}, 3, 'cache - cached 2');
+
+}
+
 ###############################################################################