Mercurial > hg > nginx-tests
annotate proxy-noclose.t @ 23:e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 29 Sep 2008 02:10:07 +0400 |
parents | 5e65db715827 |
children | fbda19df2fc4 |
rev | line source |
---|---|
21
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Test for http backend not closing connection properly after sending full |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 # reply. This is in fact backend bug, but it seems common, and anyway |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 # correct handling is required to support persistent connections. |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 ############################################################################### |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 use warnings; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use strict; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
23
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
14 use Test::More tests => 2; |
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
15 |
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
16 use IO::Select; |
21
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 BEGIN { use FindBin; chdir($FindBin::Bin); } |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 use lib 'lib'; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 use Test::Nginx; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 ############################################################################### |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 select STDERR; $| = 1; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 my $t = Test::Nginx->new(); |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 $t->write_file_expand('nginx.conf', <<'EOF'); |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 master_process off; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 daemon off; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 events { |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 worker_connections 1024; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 } |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 http { |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 access_log off; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 root %%TESTDIR%%; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 server { |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 listen localhost:8080; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 server_name localhost; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 location / { |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 proxy_pass http://localhost:8081; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 proxy_read_timeout 1s; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 } |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 } |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 } |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 EOF |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 $t->run_daemon(\&http_noclose_daemon); |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 $t->run(); |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 ############################################################################### |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 TODO: { |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 local $TODO = 'not fixed yet, submit patches'; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 |
23
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
64 like(http_request('/'), qr/TEST-OK-IF-YOU-SEE-THIS/, 'request to bad backend'); |
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
65 like(http_request('/multi'), qr/AND-THIS/, 'bad backend - multiple packets'); |
21
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 } |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 ############################################################################### |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 sub http_request { |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 my ($url) = @_; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 my $r = http(<<EOF); |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 GET $url HTTP/1.1 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 Host: localhost |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 Connection: close |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 EOF |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 } |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 sub http_noclose_daemon { |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 my $server = IO::Socket::INET->new( |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 Proto => 'tcp', |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 LocalPort => 8081, |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 Listen => 5, |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 Reuse => 1 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 ) |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 or die "Can't create listening socket: $!\n"; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 while (my $client = $server->accept()) { |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 $client->autoflush(1); |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 |
23
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
93 my $multi = 0; |
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
94 |
21
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 while (<$client>) { |
23
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
96 $multi = 1 if /multi/; |
21
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 last if (/^\x0d?\x0a?$/); |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 } |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 |
23
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
100 my $length = $multi ? 32 : 24; |
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
101 |
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
102 print $client <<"EOF"; |
21
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 HTTP/1.1 200 OK |
23
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
104 Content-Length: $length |
21
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 Connection: close |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 TEST-OK-IF-YOU-SEE-THIS |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 EOF |
23
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
109 |
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
110 if ($multi) { |
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
111 select undef, undef, undef, 0.1; |
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
112 print $client 'AND-THIS'; |
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
113 } |
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
114 |
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
115 my $select = IO::Select->new($client); |
e6b7c3b5389c
Tests: test for multiple buffers in proxy-noclose.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
22
diff
changeset
|
116 $select->can_read(2); |
21
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
117 close $client; |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
118 } |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
119 } |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
120 |
a2144333aa8f
Tests: todo test for buggy backends not closing connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
121 ############################################################################### |