Mercurial > hg > nginx-tests
annotate fastcgi_split.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 |
---|---|
380
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Test for fastcgi backend. |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 # Incorrect split headers handling after switching to next server, |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 # as reported by Lucas Molas. |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 ############################################################################### |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 use warnings; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use strict; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 use Test::More; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 use Socket qw/ CR LF CRLF /; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 use lib 'lib'; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 use Test::Nginx; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 ############################################################################### |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 eval { require FCGI; }; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 plan(skip_all => 'FCGI not installed') if $@; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 my $t = Test::Nginx->new()->has(qw/http fastcgi/)->plan(1) |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 ->write_file_expand('nginx.conf', <<'EOF'); |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 %%TEST_GLOBALS%% |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 daemon off; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 events { |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 } |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 http { |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 %%TEST_GLOBALS_HTTP%% |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 upstream u { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 server 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
46 server 127.0.0.1:8082; |
380
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 } |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
50 listen 127.0.0.1:8080; |
380
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 server_name localhost; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 location / { |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 fastcgi_pass u; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 fastcgi_param REQUEST_URI $request_uri; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 fastcgi_next_upstream invalid_header; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 } |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 } |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 } |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 EOF |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
63 $t->run_daemon(\&fastcgi_daemon, port(8081)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
64 $t->run_daemon(\&fastcgi_daemon, port(8082)); |
380
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 $t->run(); |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
68 $t->waitforsocket('127.0.0.1:' . port(8081)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
69 $t->waitforsocket('127.0.0.1:' . port(8082)); |
380
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 ############################################################################### |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 like(http_get('/'), qr/^Good: header/ms, 'fastcgi next upstream'); |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 ############################################################################### |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 sub fastcgi_daemon { |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 my ($port) = @_; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 my $socket = FCGI::OpenSocket("127.0.0.1:$port", 5); |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 $socket); |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 my $count; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 while( $request->Accept() >= 0 ) { |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 $count++; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
87 if ($port == port(8081)) { |
380
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 print 'BAD'; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 } |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
90 if ($port == port(8082)) { |
380
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 print 'Good: header' . CRLF . CRLF; |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 } |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 } |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 FCGI::CloseSocket($socket); |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 } |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 |
74a015aad352
Tests: split headers and fastcgi_next_upstream test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 ############################################################################### |