Mercurial > hg > nginx-tests
comparison proxy_cache_lock_ssi.t @ 504:318f305a2014
Tests: proxy_cache_lock with subrequests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 27 Nov 2014 08:07:52 +0300 |
parents | |
children | 5baf4b01cae4 |
comparison
equal
deleted
inserted
replaced
503:071e8941e3bf | 504:318f305a2014 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for http proxy cache lock with subrequests. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx qw/ :DEFAULT http_end /; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
24 plan(skip_all => 'win32') if $^O eq 'MSWin32'; | |
25 | |
26 my $t = Test::Nginx->new()->has(qw/http proxy cache ssi/) | |
27 ->write_file_expand('nginx.conf', <<'EOF')->plan(2); | |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 proxy_cache_path %%TESTDIR%%/cache levels=1:2 | |
40 keys_zone=NAME:1m; | |
41 | |
42 limit_req_zone $binary_remote_addr zone=one:1m rate=1r/m; | |
43 | |
44 server { | |
45 listen 127.0.0.1:8080; | |
46 server_name localhost; | |
47 | |
48 location / { | |
49 proxy_pass http://127.0.0.1:8081; | |
50 proxy_cache NAME; | |
51 | |
52 proxy_cache_lock on; | |
53 proxy_cache_lock_timeout 100ms; | |
54 | |
55 proxy_read_timeout 2s; | |
56 } | |
57 | |
58 location = /ssi.html { | |
59 ssi on; | |
60 } | |
61 } | |
62 | |
63 server { | |
64 listen 127.0.0.1:8081; | |
65 server_name localhost; | |
66 limit_req zone=one burst=5; | |
67 } | |
68 | |
69 } | |
70 | |
71 EOF | |
72 | |
73 $t->write_file('ssi.html', | |
74 '<!--#include virtual="/active" -->' . | |
75 '<!--#include virtual="/locked" -->' . | |
76 'end' | |
77 ); | |
78 | |
79 $t->write_file('active', 'active'); | |
80 $t->write_file('locked', 'locked'); | |
81 | |
82 $t->run(); | |
83 | |
84 ############################################################################### | |
85 | |
86 # problem: if proxy cache lock wakeup happens in a an inactive | |
87 # subrequest, just a connection write event may not trigger any | |
88 # further work | |
89 | |
90 # main request -> subrequest /active (waiting for a backend), | |
91 # -> subrequest /locked (locked by another request) | |
92 | |
93 # this doesn't result in an infinite timeout as second subrequest | |
94 # is woken up by the postpone filter once first subrequest completes, | |
95 # but this is suboptimal behaviour | |
96 | |
97 my $start = time(); | |
98 | |
99 my $s = http_get('/locked', start => 1); | |
100 like(http_get('/ssi.html'), qr/end/, 'cache lock ssi'); | |
101 http_end($s); | |
102 | |
103 TODO: { | |
104 local $TODO = 'not yet'; | |
105 | |
106 cmp_ok(time() - $start, '<=', 3, 'parallel execution after lock timeout'); | |
107 | |
108 } | |
109 | |
110 ############################################################################### |