Mercurial > hg > nginx-tests
annotate stream_proxy_next_upstream.t @ 565:ff49e1c00b35
Tests: in stream tests, try to read all the data where appropriate.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 29 Apr 2015 14:58:27 +0300 |
parents | cd3e32d9997e |
children | ca54b445d982 |
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 |
561
cd3e32d9997e
Tests: adjusted stream test timeouts, visible on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
554
diff
changeset
|
45 proxy_connect_timeout 1s; |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 server { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 listen 127.0.0.1:8081; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 proxy_pass u; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 proxy_next_upstream off; |
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 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 server { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 listen 127.0.0.1:8082; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 proxy_pass u; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 proxy_next_upstream on; |
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 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 server { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 listen 127.0.0.1:8083; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 proxy_pass u; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 proxy_next_upstream on; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 proxy_next_upstream_tries 2; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 EOF |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 $t->run_daemon(\&stream_daemon); |
554
4cc65166509e
Tests: removed superfluous try_run() check.
Sergey Kandaurov <pluknet@nginx.com>
parents:
553
diff
changeset
|
70 $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
|
71 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 ############################################################################### |
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 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
|
75 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
|
76 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 # make sure backup is not tried |
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:8083'), '', 'next upstream tries'); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
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 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 sub stream_get { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 my ($data, $peer) = @_; |
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 my $s = stream_connect($peer); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 stream_write($s, $data); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 |
565
ff49e1c00b35
Tests: in stream tests, try to read all the data where appropriate.
Sergey Kandaurov <pluknet@nginx.com>
parents:
561
diff
changeset
|
89 $data = ''; |
ff49e1c00b35
Tests: in stream tests, try to read all the data where appropriate.
Sergey Kandaurov <pluknet@nginx.com>
parents:
561
diff
changeset
|
90 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
|
91 $data .= $buf; |
ff49e1c00b35
Tests: in stream tests, try to read all the data where appropriate.
Sergey Kandaurov <pluknet@nginx.com>
parents:
561
diff
changeset
|
92 } |
ff49e1c00b35
Tests: in stream tests, try to read all the data where appropriate.
Sergey Kandaurov <pluknet@nginx.com>
parents:
561
diff
changeset
|
93 return $data; |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 sub stream_connect { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 my $peer = shift; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 my $s = IO::Socket::INET->new( |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 Proto => 'tcp', |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 PeerAddr => $peer |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 ) |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 or die "Can't connect to nginx: $!\n"; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 return $s; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 } |
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 sub stream_write { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 my ($s, $message) = @_; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 local $SIG{PIPE} = 'IGNORE'; |
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 $s->blocking(0); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 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
|
114 my $n = $s->syswrite($message); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 last unless $n; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 $message = substr($message, $n); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 last unless length $message; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 if (length $message) { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 $s->close(); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 } |
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 sub stream_read { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 my ($s) = @_; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 my ($buf); |
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 $s->blocking(0); |
561
cd3e32d9997e
Tests: adjusted stream test timeouts, visible on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
554
diff
changeset
|
130 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
|
131 $s->sysread($buf, 1024); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 }; |
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 log_in($buf); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 return $buf; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 } |
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 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 sub stream_daemon { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 my $server = IO::Socket::INET->new( |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 Proto => 'tcp', |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 LocalHost => '127.0.0.1:8089', |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 Listen => 5, |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 Reuse => 1 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 ) |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 or die "Can't create listening socket: $!\n"; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 local $SIG{PIPE} = 'IGNORE'; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 while (my $client = $server->accept()) { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 $client->autoflush(1); |
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 log2c("(new connection $client)"); |
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 $client->sysread(my $buffer, 65536) or next; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 log2i("$client $buffer"); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 $buffer = 'SEE-THIS'; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 log2o("$client $buffer"); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 $client->syswrite($buffer); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 } continue { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 close $client; |
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 } |
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 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 sub log2c { Test::Nginx::log_core('||', @_); } |
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 ############################################################################### |