Mercurial > hg > nginx-tests
comparison ssi_delayed.t @ 1161:e1225e304e46
Tests: special test with subrequest.
Test is checking sending data to client and clearing
proxy buffers when parent request is delayed.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Wed, 05 Apr 2017 11:21:05 +0300 |
parents | |
children | 766bcbb632ee |
comparison
equal
deleted
inserted
replaced
1160:4ed2226d47de | 1161:e1225e304e46 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Andrey Zelenkov | |
4 # (C) Roman Arutyunyan | |
5 # (C) Nginx, Inc. | |
6 | |
7 # Test for subrequest bug with delay (see 903fb1ddc07f for details). | |
8 | |
9 ############################################################################### | |
10 | |
11 use warnings; | |
12 use strict; | |
13 | |
14 use Test::More; | |
15 | |
16 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
17 | |
18 use lib 'lib'; | |
19 use Test::Nginx; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
26 my $t = Test::Nginx->new()->has(qw/http proxy ssi/)->plan(1); | |
27 | |
28 $t->write_file_expand('nginx.conf', <<'EOF'); | |
29 | |
30 %%TEST_GLOBALS%% | |
31 | |
32 daemon off; | |
33 | |
34 events { | |
35 } | |
36 | |
37 http { | |
38 %%TEST_GLOBALS_HTTP%% | |
39 | |
40 server { | |
41 listen 127.0.0.1:8080; | |
42 server_name localhost; | |
43 | |
44 location / { } | |
45 location /delayed.html { | |
46 ssi on; | |
47 sendfile_max_chunk 100; | |
48 postpone_output 0; | |
49 } | |
50 | |
51 location /1 { | |
52 proxy_buffers 3 256; | |
53 proxy_buffer_size 256; | |
54 proxy_max_temp_file_size 0; | |
55 proxy_pass http://127.0.0.1:8081; | |
56 } | |
57 } | |
58 } | |
59 | |
60 EOF | |
61 | |
62 | |
63 $t->write_file('delayed.html', ('x' x 100) . '<!--#include virtual="/1"-->'); | |
64 | |
65 $t->run_daemon(\&http_daemon); | |
66 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); | |
67 | |
68 ############################################################################### | |
69 | |
70 TODO: { | |
71 local $TODO = 'not yet' unless $t->has_version('1.11.13'); | |
72 | |
73 # If a response sending is delayed by sendfile_max_chunk, and | |
74 # then we've switched to a different subrequest, which is not yet | |
75 # ready to handle corresponding write event, wev->delayed won't be | |
76 # cleared. This results in the subrequest response not being | |
77 # sent to the client, and the whole request will hang if all proxy | |
78 # buffers will be exhausted. Fixed in 1.11.13 (903fb1ddc07f). | |
79 | |
80 like(http_get('/delayed.html'), qr/x{100}y{1024}SEE-THIS/, 'delayed'); | |
81 | |
82 } | |
83 | |
84 ############################################################################### | |
85 | |
86 sub http_daemon { | |
87 my ($t) = @_; | |
88 | |
89 my $server = IO::Socket::INET->new( | |
90 Proto => 'tcp', | |
91 LocalHost => '127.0.0.1', | |
92 LocalPort => port(8081), | |
93 Listen => 5, | |
94 Reuse => 1 | |
95 ) | |
96 or die "Can't create listening socket: $!\n"; | |
97 | |
98 local $SIG{PIPE} = 'IGNORE'; | |
99 | |
100 my $data = ('y' x 1024) . 'SEE-THIS'; | |
101 | |
102 while (my $client = $server->accept()) { | |
103 $client->autoflush(1); | |
104 | |
105 my $headers = ''; | |
106 | |
107 while (<$client>) { | |
108 $headers .= $_; | |
109 last if (/^\x0d?\x0a?$/); | |
110 } | |
111 | |
112 select undef, undef, undef, 0.5; | |
113 | |
114 print $client <<EOF; | |
115 HTTP/1.1 200 OK | |
116 Connection: close | |
117 | |
118 $data | |
119 EOF | |
120 } | |
121 } | |
122 | |
123 ############################################################################### |