Mercurial > hg > nginx-tests
annotate fastcgi_buffering.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 882267679006 |
children |
rev | line source |
---|---|
336
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Test for fastcgi backend with fastcgi_buffering off. |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 use Socket qw/ CRLF /; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 use lib 'lib'; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 use Test::Nginx; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 ############################################################################### |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 eval { require FCGI; }; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 plan(skip_all => 'FCGI not installed') if $@; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 my $t = Test::Nginx->new()->has(qw/http fastcgi ssi/) |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 ->write_file_expand('nginx.conf', <<'EOF'); |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 %%TEST_GLOBALS%% |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 daemon off; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 events { |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 } |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 http { |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 %%TEST_GLOBALS_HTTP%% |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
44 listen 127.0.0.1:8080; |
336
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 server_name localhost; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
48 fastcgi_pass 127.0.0.1:8081; |
336
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 fastcgi_param REQUEST_URI $request_uri; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 fastcgi_buffering off; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 } |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 location /inmemory.html { |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 ssi on; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 } |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 } |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 } |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 EOF |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 $t->write_file('inmemory.html', |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 '<!--#include virtual="/include$request_uri" set="x" -->' . |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 'set: <!--#echo var="x" -->'); |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 |
397
847ea345becb
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
392
diff
changeset
|
65 $t->run()->plan(2); |
336
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
67 $t->run_daemon(\&fastcgi_daemon)->waitforsocket('127.0.0.1:' . port(8081)); |
336
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 ############################################################################### |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 like(http_get('/'), qr/SEE-THIS/, 'fastcgi unbuffered'); |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 like(http_get('/inmemory.html'), qr/set: SEE-THIS/, 'fastcgi inmemory'); |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 ############################################################################### |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 sub fastcgi_daemon { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
77 my $socket = FCGI::OpenSocket('127.0.0.1:' . port(8081), 5); |
336
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 $socket); |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 my $count; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 while( $request->Accept() >= 0 ) { |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 $count++; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 # this intentionally uses multiple print()'s to test |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 # parsing of multiple records |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 print( |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 "Status: 200 OK" . CRLF . |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 "Content-Type: text/plain" . CRLF . CRLF |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 ); |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 print "SEE"; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 print "-THIS" . CRLF; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 print "$count" . CRLF; |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 } |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 FCGI::CloseSocket($socket); |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 } |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 |
b6c7db85bad0
Tests: fastcgi_buffering tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 ############################################################################### |