Mercurial > hg > nginx-tests
comparison proxy-noclose.t @ 21:a2144333aa8f
Tests: todo test for buggy backends not closing connections.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 26 Sep 2008 18:28:02 +0400 |
parents | |
children | 5e65db715827 |
comparison
equal
deleted
inserted
replaced
20:c57e8bd7bfc7 | 21:a2144333aa8f |
---|---|
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 ############################################################################### | |
10 | |
11 use warnings; | |
12 use strict; | |
13 | |
14 use Test::More tests => 1; | |
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(); | |
27 | |
28 $t->write_file_expand('nginx.conf', <<'EOF'); | |
29 | |
30 master_process off; | |
31 daemon off; | |
32 | |
33 events { | |
34 worker_connections 1024; | |
35 } | |
36 | |
37 http { | |
38 access_log off; | |
39 root %%TESTDIR%%; | |
40 | |
41 server { | |
42 listen localhost:8080; | |
43 server_name localhost; | |
44 | |
45 location / { | |
46 proxy_pass http://localhost:8081; | |
47 proxy_read_timeout 1s; | |
48 } | |
49 } | |
50 } | |
51 | |
52 EOF | |
53 | |
54 $t->run_daemon(\&http_noclose_daemon); | |
55 $t->run(); | |
56 | |
57 ############################################################################### | |
58 | |
59 TODO: { | |
60 local $TODO = 'not fixed yet, submit patches'; | |
61 | |
62 my $t1 = http_request('/'); | |
63 like($t1, qr/TEST-OK-IF-YOU-SEE-THIS/, 'request to bad backend'); | |
64 | |
65 } | |
66 | |
67 ############################################################################### | |
68 | |
69 sub http_request { | |
70 my ($url) = @_; | |
71 my $r = http(<<EOF); | |
72 GET $url HTTP/1.1 | |
73 Host: localhost | |
74 Connection: close | |
75 | |
76 EOF | |
77 } | |
78 | |
79 sub http_noclose_daemon { | |
80 my $server = IO::Socket::INET->new( | |
81 Proto => 'tcp', | |
82 LocalPort => 8081, | |
83 Listen => 5, | |
84 Reuse => 1 | |
85 ) | |
86 or die "Can't create listening socket: $!\n"; | |
87 | |
88 while (my $client = $server->accept()) { | |
89 $client->autoflush(1); | |
90 | |
91 while (<$client>) { | |
92 last if (/^\x0d?\x0a?$/); | |
93 } | |
94 | |
95 print $client <<'EOF'; | |
96 HTTP/1.1 200 OK | |
97 Content-Length: 23 | |
98 Connection: close | |
99 | |
100 TEST-OK-IF-YOU-SEE-THIS | |
101 EOF | |
102 sleep 2; | |
103 close $client; | |
104 } | |
105 } | |
106 | |
107 ############################################################################### |