Mercurial > hg > nginx-tests
annotate proxy_cache_lock_ssi.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | be45fa007655 |
children |
rev | line source |
---|---|
504
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for http proxy cache lock with subrequests. |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx qw/ :DEFAULT http_end /; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy cache ssi/) |
504
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 ->write_file_expand('nginx.conf', <<'EOF')->plan(2); |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 %%TEST_GLOBALS%% |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 daemon off; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 events { |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 } |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 http { |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 %%TEST_GLOBALS_HTTP%% |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 proxy_cache_path %%TESTDIR%%/cache levels=1:2 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 keys_zone=NAME:1m; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 limit_req_zone $binary_remote_addr zone=one:1m rate=1r/m; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 listen 127.0.0.1:8080; |
504
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 server_name localhost; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
47 proxy_pass http://127.0.0.1:8081; |
504
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 proxy_cache NAME; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 proxy_cache_lock on; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 proxy_cache_lock_timeout 100ms; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 |
640
1d1eaf5ce064
Tests: adjusted proxy_cache_lock_ssi.t test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
596
diff
changeset
|
53 proxy_read_timeout 3s; |
504
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 } |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 location = /ssi.html { |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 ssi on; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 } |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 } |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
62 listen 127.0.0.1:8081; |
504
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 server_name localhost; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 limit_req zone=one burst=5; |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 } |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 } |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 EOF |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 $t->write_file('ssi.html', |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 '<!--#include virtual="/active" -->' . |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 '<!--#include virtual="/locked" -->' . |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 'end' |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 ); |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 $t->write_file('active', 'active'); |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 $t->write_file('locked', 'locked'); |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 $t->run(); |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 ############################################################################### |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 |
1031
be45fa007655
Tests: fixed test preconditions in proxy_cache_lock_ssi.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
84 # problem: if proxy cache lock wakeup happens in an inactive |
504
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 # subrequest, just a connection write event may not trigger any |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 # further work |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 # main request -> subrequest /active (waiting for a backend), |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 # -> subrequest /locked (locked by another request) |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 # this doesn't result in an infinite timeout as second subrequest |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 # is woken up by the postpone filter once first subrequest completes, |
596
e36b267021e3
Tests: partially reverted 6cdfd177319b.
Maxim Dounin <mdounin@mdounin.ru>
parents:
595
diff
changeset
|
93 # but this is suboptimal behaviour |
504
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 |
1031
be45fa007655
Tests: fixed test preconditions in proxy_cache_lock_ssi.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
95 http_get('/charge'); |
be45fa007655
Tests: fixed test preconditions in proxy_cache_lock_ssi.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
96 my $start = time(); |
be45fa007655
Tests: fixed test preconditions in proxy_cache_lock_ssi.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
97 |
504
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 my $s = http_get('/locked', start => 1); |
1031
be45fa007655
Tests: fixed test preconditions in proxy_cache_lock_ssi.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
99 select undef, undef, undef, 0.2; |
be45fa007655
Tests: fixed test preconditions in proxy_cache_lock_ssi.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
100 |
504
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 like(http_get('/ssi.html'), qr/end/, 'cache lock ssi'); |
1031
be45fa007655
Tests: fixed test preconditions in proxy_cache_lock_ssi.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
102 http_end($s); |
640
1d1eaf5ce064
Tests: adjusted proxy_cache_lock_ssi.t test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
596
diff
changeset
|
103 cmp_ok(time() - $start, '<=', 5, 'parallel execution after lock timeout'); |
504
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 |
318f305a2014
Tests: proxy_cache_lock with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 ############################################################################### |