Mercurial > hg > nginx-tests
annotate scgi_cache.t @ 1215:26884729e06b
Tests: cope with resolver resend in mail resolver tests.
Currently, if resolver didn't find PTR type in the answer section of PTR
response, it keeps the node in the resend queue until the next timer event.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 31 Aug 2017 19:09:04 +0300 |
parents | 196d33c2bb45 |
children |
rev | line source |
---|---|
308 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for scgi_cache. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 use Socket qw/ CRLF /; | |
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 eval { require SCGI; }; | |
26 plan(skip_all => 'SCGI not installed') if $@; | |
27 | |
1020
196d33c2bb45
Tests: removed TODO and try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/http scgi cache/)->plan(10) |
308 | 29 ->write_file_expand('nginx.conf', <<'EOF'); |
30 | |
31 %%TEST_GLOBALS%% | |
32 | |
33 daemon off; | |
34 | |
35 events { | |
36 } | |
37 | |
38 http { | |
39 %%TEST_GLOBALS_HTTP%% | |
40 | |
41 scgi_cache_path %%TESTDIR%%/cache keys_zone=one:1m; | |
42 scgi_cache_key $request_uri; | |
43 | |
44 add_header X-Cache-Status $upstream_cache_status; | |
45 | |
46 server { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
47 listen 127.0.0.1:8080; |
308 | 48 server_name localhost; |
49 | |
50 location / { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
51 scgi_pass 127.0.0.1:8081; |
308 | 52 scgi_param SCGI 1; |
53 scgi_param REQUEST_URI $uri; | |
54 scgi_cache one; | |
55 } | |
56 } | |
57 } | |
58 | |
59 EOF | |
60 | |
61 $t->run_daemon(\&scgi_daemon); | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
62 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
308 | 63 |
64 ############################################################################### | |
65 | |
66 like(http_get('/len'), qr/MISS/, 'length'); | |
67 like(http_get('/len'), qr/HIT/, 'length cached'); | |
68 | |
69 like(http_get('/nolen'), qr/MISS/, 'no length'); | |
70 like(http_get('/nolen'), qr/HIT/, 'no length cached'); | |
71 | |
72 like(http_get('/len/empty'), qr/MISS/, 'empty length'); | |
73 like(http_get('/len/empty'), qr/HIT/, 'empty length cached'); | |
74 | |
75 like(http_get('/nolen/empty'), qr/MISS/, 'empty no length'); | |
76 like(http_get('/nolen/empty'), qr/HIT/, 'empty no length cached'); | |
77 | |
78 like(http_get('/unfinished'), qr/MISS/, 'unfinished'); | |
79 like(http_get('/unfinished'), qr/MISS/, 'unfinished not cached'); | |
80 | |
81 ############################################################################### | |
82 | |
83 sub scgi_daemon { | |
84 my $server = IO::Socket::INET->new( | |
85 Proto => 'tcp', | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
86 LocalHost => '127.0.0.1:' . port(8081), |
308 | 87 Listen => 5, |
88 Reuse => 1 | |
89 ) | |
90 or die "Can't create listening socket: $!\n"; | |
91 | |
92 my $scgi = SCGI->new($server, blocking => 1); | |
93 my %count; | |
94 | |
95 while (my $request = $scgi->accept()) { | |
960
d4a0232425ee
Tests: fixed race in SCGI tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
96 eval { $request->read_env(); }; |
d4a0232425ee
Tests: fixed race in SCGI tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
97 next if $@; |
308 | 98 |
99 my $uri = $request->env->{REQUEST_URI} || ''; | |
100 my $c = $request->connection(); | |
101 | |
102 $count{$uri} ||= 0; | |
103 $count{$uri}++; | |
104 | |
105 if ($uri eq '/len') { | |
106 $c->print( | |
107 "Content-Length: 9" . CRLF . | |
108 "Content-Type: text/html" . CRLF . | |
109 "Cache-Control: max-age=300" . CRLF . CRLF . | |
110 "test body" | |
111 ); | |
112 | |
113 } elsif ($uri eq '/nolen') { | |
114 $c->print( | |
115 "Content-Type: text/html" . CRLF . | |
116 "Cache-Control: max-age=300" . CRLF . CRLF . | |
117 "test body" | |
118 ); | |
119 | |
120 } elsif ($uri eq '/len/empty') { | |
121 $c->print( | |
122 "Content-Length: 0" . CRLF . | |
123 "Content-Type: text/html" . CRLF . | |
124 "Cache-Control: max-age=300" . CRLF . CRLF | |
125 ); | |
126 | |
127 } elsif ($uri eq '/nolen/empty') { | |
128 $c->print( | |
129 "Content-Type: text/html" . CRLF . | |
130 "Cache-Control: max-age=300" . CRLF . CRLF | |
131 ); | |
132 | |
133 } elsif ($uri eq '/unfinished') { | |
134 $c->print( | |
135 "Content-Length: 10" . CRLF . | |
136 "Content-Type: text/html" . CRLF . | |
137 "Cache-Control: max-age=300" . CRLF . CRLF | |
138 ); | |
139 } | |
140 } | |
141 } | |
142 | |
143 ############################################################################### |