comparison proxy_cache_manager.t @ 1048:f38301fd4792

Tests: basic proxy cache manager tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 05 Oct 2016 16:08:24 +0300
parents
children c65e5c0e2980
comparison
equal deleted inserted replaced
1047:ef795982f940 1048:f38301fd4792
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for http proxy cache, manager parameters.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 plan(skip_all => 'long test') unless $ENV{TEST_NGINX_UNSAFE};
26
27 my $t = Test::Nginx->new()->has(qw/http proxy cache/)
28 ->write_file_expand('nginx.conf', <<'EOF');
29
30 %%TEST_GLOBALS%%
31
32 daemon off;
33
34 events {
35 }
36
37 http {
38 %%TEST_GLOBALS_HTTP%%
39
40 proxy_cache_path %%TESTDIR%%/cache max_size=0 keys_zone=NAME:1m
41 manager_sleep=5 manager_files=2 manager_threshold=10;
42
43 server {
44 listen 127.0.0.1:8080;
45 server_name localhost;
46
47 location / {
48 proxy_pass http://127.0.0.1:8081;
49 proxy_cache NAME;
50
51 proxy_cache_valid any 1m;
52 }
53 }
54
55 server {
56 listen 127.0.0.1:8081;
57 server_name localhost;
58
59 location / { }
60 }
61 }
62
63 EOF
64
65 $t->write_file('t.html', 'SEE-THIS');
66 $t->try_run('no manager params')->plan(2);
67
68 ###############################################################################
69
70 http_get("/t.html?$_") for (1 .. 5);
71
72 # wait for cache manager
73
74 sleep 11;
75
76 opendir(my $dh, $t->testdir() . '/cache');
77 my $files = grep { ! /^\./ } readdir($dh);
78 is($files, 3, 'manager files');
79
80 sleep 5;
81
82 opendir($dh, $t->testdir() . '/cache');
83 $files = grep { ! /^\./ } readdir($dh);
84 is($files, 1, 'manager sleep');
85
86 ###############################################################################