comparison proxy_noclose.t @ 148:b714d6df958c

Tests: rename some tests for better sorting. Use underscore instead of dash. Addtionally, rename some tests to better match "module" + "details" scheme used: use "http_" prefix for http core module tests, use "mail_" prefix for mail module tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 04 Mar 2011 16:07:15 +0300
parents proxy-noclose.t@8ac1faaddd2c
children c0ae29632905
comparison
equal deleted inserted replaced
147:fd865ada95c8 148:b714d6df958c
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
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
7 # correct handling is required to support persistent connections.
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
16 ###############################################################################
17
18 use warnings;
19 use strict;
20
21 use Test::More;
22
23 use IO::Select;
24
25 BEGIN { use FindBin; chdir($FindBin::Bin); }
26
27 use lib 'lib';
28 use Test::Nginx;
29
30 ###############################################################################
31
32 select STDERR; $| = 1;
33 select STDOUT; $| = 1;
34
35 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(4);
36
37 $t->write_file_expand('nginx.conf', <<'EOF');
38
39 %%TEST_GLOBALS%%
40
41 master_process off;
42 daemon off;
43
44 events {
45 }
46
47 http {
48 %%TEST_GLOBALS_HTTP%%
49
50 server {
51 listen 127.0.0.1:8080;
52 server_name localhost;
53
54 location / {
55 proxy_pass http://127.0.0.1:8081;
56 proxy_read_timeout 1s;
57 }
58
59 location /uselen {
60 proxy_pass http://127.0.0.1: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 }
67 }
68 }
69
70 EOF
71
72 $t->run_daemon(\&http_noclose_daemon);
73 $t->run();
74
75 ###############################################################################
76
77 TODO: {
78 local $TODO = 'not fixed yet, patches under review';
79 local $SIG{__WARN__} = sub {};
80
81 like(http_get('/'), qr/SEE-THIS/, 'request to bad backend');
82 like(http_get('/multi'), qr/AND-THIS/, 'bad backend - multiple packets');
83 like(http_get('/nolen'), qr/SEE-THIS/, 'bad backend - no content length');
84 like(http_get('/uselen'), qr/SEE-THIS/, 'content-length actually used');
85
86 }
87
88 ###############################################################################
89
90 sub http_noclose_daemon {
91 my $server = IO::Socket::INET->new(
92 Proto => 'tcp',
93 LocalAddr => '127.0.0.1:8081',
94 Listen => 5,
95 Reuse => 1
96 )
97 or die "Can't create listening socket: $!\n";
98
99 while (my $client = $server->accept()) {
100 $client->autoflush(1);
101
102 my $multi = 0;
103 my $nolen = 0;
104
105 while (<$client>) {
106 $multi = 1 if /multi/;
107 $nolen = 1 if /nolen/;
108 last if (/^\x0d?\x0a?$/);
109 }
110
111 if ($nolen) {
112
113 print $client <<'EOF';
114 HTTP/1.1 200 OK
115 Connection: close
116
117 TEST-OK-IF-YOU-SEE-THIS
118 EOF
119 } elsif ($multi) {
120
121 print $client <<"EOF";
122 HTTP/1.1 200 OK
123 Content-Length: 32
124 Connection: close
125
126 TEST-OK-IF-YOU-SEE-THIS
127 EOF
128
129 select undef, undef, undef, 0.1;
130 print $client 'AND-THIS';
131
132 } else {
133
134 print $client <<"EOF";
135 HTTP/1.1 200 OK
136 Content-Length: 24
137 Connection: close
138
139 TEST-OK-IF-YOU-SEE-THIS
140 EOF
141 }
142
143 my $select = IO::Select->new($client);
144 $select->can_read(10);
145 close $client;
146 }
147 }
148
149 ###############################################################################