comparison proxy-noclose.t @ 25:fbda19df2fc4

Tests: more proxy-noclose tests. 1. Make sure data got from upstream are flushed in case of upstream timeout (and so everything is ok even if we got no Content-Length). 2. Additional test that checks if nginx actually uses Content-Length info. This one will fail if nginx will wait for upstream timeout instead of sending response as soon as it got full body.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 30 Sep 2008 22:58:25 +0400
parents e6b7c3b5389c
children 71ea39729fa0
comparison
equal deleted inserted replaced
24:89b00444c168 25:fbda19df2fc4
4 4
5 # Test for http backend not closing connection properly after sending full 5 # Test for http backend not closing connection properly after sending full
6 # reply. This is in fact backend bug, but it seems common, and anyway 6 # reply. This is in fact backend bug, but it seems common, and anyway
7 # correct handling is required to support persistent connections. 7 # correct handling is required to support persistent connections.
8 8
9 # There are actually 2 nginx problems here:
10 #
11 # 1. It doesn't send reply in-time even if got Content-Length and all the data.
12 #
13 # 2. If upstream times out some data may be left in input buffer and won't be
14 # sent to downstream.
15
9 ############################################################################### 16 ###############################################################################
10 17
11 use warnings; 18 use warnings;
12 use strict; 19 use strict;
13 20
14 use Test::More tests => 2; 21 use Test::More tests => 4;
15 22
16 use IO::Select; 23 use IO::Select;
17 24
18 BEGIN { use FindBin; chdir($FindBin::Bin); } 25 BEGIN { use FindBin; chdir($FindBin::Bin); }
19 26
46 53
47 location / { 54 location / {
48 proxy_pass http://localhost:8081; 55 proxy_pass http://localhost:8081;
49 proxy_read_timeout 1s; 56 proxy_read_timeout 1s;
50 } 57 }
58
59 location /uselen {
60 proxy_pass http://localhost:8081;
61
62 # test will wait only 2s for reply, we it will fail if
63 # Content-Length not used as a hint
64
65 proxy_read_timeout 10s;
66 }
51 } 67 }
52 } 68 }
53 69
54 EOF 70 EOF
55 71
57 $t->run(); 73 $t->run();
58 74
59 ############################################################################### 75 ###############################################################################
60 76
61 TODO: { 77 TODO: {
62 local $TODO = 'not fixed yet, submit patches'; 78 local $TODO = 'not fixed yet, patches under review';
63 79
64 like(http_request('/'), qr/TEST-OK-IF-YOU-SEE-THIS/, 'request to bad backend'); 80 like(http_request('/'), qr/SEE-THIS/, 'request to bad backend');
65 like(http_request('/multi'), qr/AND-THIS/, 'bad backend - multiple packets'); 81 like(http_request('/multi'), qr/AND-THIS/, 'bad backend - multiple packets');
82 like(http_request('/nolen'), qr/SEE-THIS/, 'bad backend - no content length');
83 like(http_request('/uselen'), qr/SEE-THIS/, 'content-length actually used');
66 84
67 } 85 }
68 86
69 ############################################################################### 87 ###############################################################################
70 88
89 107
90 while (my $client = $server->accept()) { 108 while (my $client = $server->accept()) {
91 $client->autoflush(1); 109 $client->autoflush(1);
92 110
93 my $multi = 0; 111 my $multi = 0;
112 my $nolen = 0;
94 113
95 while (<$client>) { 114 while (<$client>) {
96 $multi = 1 if /multi/; 115 $multi = 1 if /multi/;
116 $nolen = 1 if /nolen/;
97 last if (/^\x0d?\x0a?$/); 117 last if (/^\x0d?\x0a?$/);
98 } 118 }
99 119
100 my $length = $multi ? 32 : 24; 120 if ($nolen) {
101 121
102 print $client <<"EOF"; 122 print $client <<'EOF';
103 HTTP/1.1 200 OK 123 HTTP/1.1 200 OK
104 Content-Length: $length 124 Connection: close
125
126 TEST-OK-IF-YOU-SEE-THIS
127 EOF
128 } elsif ($multi) {
129
130 print $client <<"EOF";
131 HTTP/1.1 200 OK
132 Content-Length: 32
105 Connection: close 133 Connection: close
106 134
107 TEST-OK-IF-YOU-SEE-THIS 135 TEST-OK-IF-YOU-SEE-THIS
108 EOF 136 EOF
109 137
110 if ($multi) {
111 select undef, undef, undef, 0.1; 138 select undef, undef, undef, 0.1;
112 print $client 'AND-THIS'; 139 print $client 'AND-THIS';
140
141 } else {
142
143 print $client <<"EOF";
144 HTTP/1.1 200 OK
145 Content-Length: 24
146 Connection: close
147
148 TEST-OK-IF-YOU-SEE-THIS
149 EOF
113 } 150 }
114 151
115 my $select = IO::Select->new($client); 152 my $select = IO::Select->new($client);
116 $select->can_read(2); 153 $select->can_read(10);
117 close $client; 154 close $client;
118 } 155 }
119 } 156 }
120 157
121 ############################################################################### 158 ###############################################################################