Mercurial > hg > nginx-tests
annotate stream_proxy_next_upstream.t @ 572:ca54b445d982
Tests: masked nginx bug in proxy next upstream.
When iterating through several next upstreams per a worker cycle,
a previously reported event about upstream connection error may
be improperly applied to the next upstream, thus leading to the
invalid connection error. E.g., in kqueue, where the problem is
visible, this is caused by "ev->instance" that does not tolerate
more than one next upstream at once, and kevents placed on the
kqueue separately for read and write events.
The change is to limit test case to the only one next upstream.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 14 May 2015 11:54:24 +0300 |
parents | ff49e1c00b35 |
children | 77359b849cd5 |
rev | line source |
---|---|
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream proxy module, proxy_next_upstream directive and friends. |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 use IO::Select; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
554
4cc65166509e
Tests: removed superfluous try_run() check.
Sergey Kandaurov <pluknet@nginx.com>
parents:
553
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/stream/)->plan(3); |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 $t->write_file_expand('nginx.conf', <<'EOF'); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 stream { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 upstream u { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 server 127.0.0.1:8087 max_fails=0; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server 127.0.0.1:8088 max_fails=0; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 server 127.0.0.1:8089 backup; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
572
ca54b445d982
Tests: masked nginx bug in proxy next upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
45 upstream u2 { |
ca54b445d982
Tests: masked nginx bug in proxy next upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
46 server 127.0.0.1:8087; |
ca54b445d982
Tests: masked nginx bug in proxy next upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
47 server 127.0.0.1:8089 backup; |
ca54b445d982
Tests: masked nginx bug in proxy next upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
48 } |
ca54b445d982
Tests: masked nginx bug in proxy next upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
49 |
561
cd3e32d9997e
Tests: adjusted stream test timeouts, visible on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
554
diff
changeset
|
50 proxy_connect_timeout 1s; |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 server { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 listen 127.0.0.1:8081; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 proxy_pass u; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 proxy_next_upstream off; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 server { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 listen 127.0.0.1:8082; |
572
ca54b445d982
Tests: masked nginx bug in proxy next upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
60 proxy_pass u2; |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 proxy_next_upstream on; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 server { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 listen 127.0.0.1:8083; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 proxy_pass u; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 proxy_next_upstream on; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 proxy_next_upstream_tries 2; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 EOF |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 $t->run_daemon(\&stream_daemon); |
554
4cc65166509e
Tests: removed superfluous try_run() check.
Sergey Kandaurov <pluknet@nginx.com>
parents:
553
diff
changeset
|
75 $t->run()->waitforsocket('127.0.0.1:8089'); |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 ############################################################################### |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 is(stream_get('.', '127.0.0.1:8081'), '', 'next upstream off'); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 is(stream_get('.', '127.0.0.1:8082'), 'SEE-THIS', 'next upstream on'); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 # make sure backup is not tried |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 is(stream_get('.', '127.0.0.1:8083'), '', 'next upstream tries'); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 ############################################################################### |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 sub stream_get { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 my ($data, $peer) = @_; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 my $s = stream_connect($peer); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 stream_write($s, $data); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
565
ff49e1c00b35
Tests: in stream tests, try to read all the data where appropriate.
Sergey Kandaurov <pluknet@nginx.com>
parents:
561
diff
changeset
|
94 $data = ''; |
ff49e1c00b35
Tests: in stream tests, try to read all the data where appropriate.
Sergey Kandaurov <pluknet@nginx.com>
parents:
561
diff
changeset
|
95 while (my $buf = stream_read($s)) { |
ff49e1c00b35
Tests: in stream tests, try to read all the data where appropriate.
Sergey Kandaurov <pluknet@nginx.com>
parents:
561
diff
changeset
|
96 $data .= $buf; |
ff49e1c00b35
Tests: in stream tests, try to read all the data where appropriate.
Sergey Kandaurov <pluknet@nginx.com>
parents:
561
diff
changeset
|
97 } |
ff49e1c00b35
Tests: in stream tests, try to read all the data where appropriate.
Sergey Kandaurov <pluknet@nginx.com>
parents:
561
diff
changeset
|
98 return $data; |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 sub stream_connect { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 my $peer = shift; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 my $s = IO::Socket::INET->new( |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 Proto => 'tcp', |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 PeerAddr => $peer |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 ) |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 or die "Can't connect to nginx: $!\n"; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 return $s; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 sub stream_write { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 my ($s, $message) = @_; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 local $SIG{PIPE} = 'IGNORE'; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 $s->blocking(0); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 while (IO::Select->new($s)->can_write(1.5)) { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 my $n = $s->syswrite($message); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 last unless $n; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 $message = substr($message, $n); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 last unless length $message; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 if (length $message) { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 $s->close(); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 sub stream_read { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 my ($s) = @_; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 my ($buf); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 $s->blocking(0); |
561
cd3e32d9997e
Tests: adjusted stream test timeouts, visible on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
554
diff
changeset
|
135 if (IO::Select->new($s)->can_read(5)) { |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 $s->sysread($buf, 1024); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 }; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 log_in($buf); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 return $buf; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 ############################################################################### |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 sub stream_daemon { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 my $server = IO::Socket::INET->new( |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 Proto => 'tcp', |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 LocalHost => '127.0.0.1:8089', |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 Listen => 5, |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 Reuse => 1 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 ) |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 or die "Can't create listening socket: $!\n"; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 local $SIG{PIPE} = 'IGNORE'; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 while (my $client = $server->accept()) { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 $client->autoflush(1); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 log2c("(new connection $client)"); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 $client->sysread(my $buffer, 65536) or next; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 log2i("$client $buffer"); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 $buffer = 'SEE-THIS'; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 log2o("$client $buffer"); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 $client->syswrite($buffer); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 } continue { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 close $client; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 sub log2c { Test::Nginx::log_core('||', @_); } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 ############################################################################### |