Mercurial > hg > nginx-tests
annotate fastcgi_cache.t @ 1025:94f8cd9b41dc
Tests: stream $status tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 05 Sep 2016 22:57:44 +0300 |
parents | 196d33c2bb45 |
children |
rev | line source |
---|---|
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Test for fastcgi backend with cache. |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 eval { require FCGI; }; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 plan(skip_all => 'FCGI not installed') if $@; |
221
8d2c6358d830
Tests: avoid using FCGI on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
212
diff
changeset
|
26 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
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 fastcgi cache/)->plan(5) |
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 ->write_file_expand('nginx.conf', <<'EOF'); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
221
diff
changeset
|
33 daemon off; |
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 events { |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 http { |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 fastcgi_cache_path %%TESTDIR%%/cache levels=1:2 |
503
071e8941e3bf
Tests: reduce shared memory zone sizes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
490
diff
changeset
|
42 keys_zone=NAME:1m; |
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 listen 127.0.0.1:8080; |
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 server_name localhost; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
49 fastcgi_pass 127.0.0.1:8081; |
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 fastcgi_param REQUEST_URI $request_uri; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 fastcgi_cache NAME; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 fastcgi_cache_key $request_uri; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 fastcgi_cache_valid 302 1m; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 EOF |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 $t->run_daemon(\&fastcgi_daemon); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
61 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 ############################################################################### |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 |
358
ec9f4f2e67e8
Tests: check if fastcgi body is cached.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
65 like(http_get('/'), qr/SEE-THIS.*^1$/ms, 'fastcgi request'); |
ec9f4f2e67e8
Tests: check if fastcgi body is cached.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
66 like(http_get('/'), qr/SEE-THIS.*^1$/ms, 'fastcgi request cached'); |
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 unlike(http_head('/'), qr/SEE-THIS/, 'no data in cached HEAD'); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 |
490
65d2d372ee31
Tests: skipped unstable fastcgi cache tests with large stderr.
Sergey Kandaurov <pluknet@nginx.com>
parents:
358
diff
changeset
|
70 SKIP: { |
65d2d372ee31
Tests: skipped unstable fastcgi cache tests with large stderr.
Sergey Kandaurov <pluknet@nginx.com>
parents:
358
diff
changeset
|
71 skip 'broken with header crossing buffer boundary', 2 |
65d2d372ee31
Tests: skipped unstable fastcgi cache tests with large stderr.
Sergey Kandaurov <pluknet@nginx.com>
parents:
358
diff
changeset
|
72 unless $ENV{TEST_NGINX_UNSAFE}; |
65d2d372ee31
Tests: skipped unstable fastcgi cache tests with large stderr.
Sergey Kandaurov <pluknet@nginx.com>
parents:
358
diff
changeset
|
73 |
358
ec9f4f2e67e8
Tests: check if fastcgi body is cached.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
74 like(http_get('/stderr'), qr/SEE-THIS.*^2$/ms, 'large stderr handled'); |
ec9f4f2e67e8
Tests: check if fastcgi body is cached.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
75 like(http_get('/stderr'), qr/SEE-THIS.*^2$/ms, 'large stderr cached'); |
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 |
490
65d2d372ee31
Tests: skipped unstable fastcgi cache tests with large stderr.
Sergey Kandaurov <pluknet@nginx.com>
parents:
358
diff
changeset
|
77 } |
65d2d372ee31
Tests: skipped unstable fastcgi cache tests with large stderr.
Sergey Kandaurov <pluknet@nginx.com>
parents:
358
diff
changeset
|
78 |
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 ############################################################################### |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 sub fastcgi_daemon { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
82 my $socket = FCGI::OpenSocket('127.0.0.1:' . port(8081), 5); |
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 $socket); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 my $count; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 while( $request->Accept() >= 0 ) { |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 $count++; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 if ($ENV{REQUEST_URI} eq '/stderr') { |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 warn "sample stderr text" x 512; |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 } |
212 | 93 |
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 print <<EOF; |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
580
diff
changeset
|
95 Location: http://localhost/redirect |
130
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 Content-Type: text/html |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 SEE-THIS |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 $count |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 EOF |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 FCGI::CloseSocket($socket); |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 } |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 |
df9a573fde22
Tests: add test for fastcgi cache problem fixed in 0.8.34.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 ############################################################################### |