annotate stream_proxy_next_upstream.t @ 554:4cc65166509e

Tests: removed superfluous try_run() check.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 22 Apr 2015 14:38:24 +0300
parents e47cd1b95997
children cd3e32d9997e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 proxy_connect_timeout 2s;
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 my $r = stream_read($s);
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 $s->close;
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 return $r;
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 }
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 sub stream_connect {
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 my $peer = shift;
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 my $s = IO::Socket::INET->new(
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 Proto => 'tcp',
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 PeerAddr => $peer
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 or die "Can't connect to nginx: $!\n";
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 return $s;
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
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 sub stream_write {
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 my ($s, $message) = @_;
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 local $SIG{PIPE} = 'IGNORE';
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 $s->blocking(0);
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 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
112 my $n = $s->syswrite($message);
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 last unless $n;
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 $message = substr($message, $n);
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 last unless length $message;
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
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 if (length $message) {
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 $s->close();
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 }
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 }
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 sub stream_read {
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 my ($s) = @_;
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 my ($buf);
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 $s->blocking(0);
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 if (IO::Select->new($s)->can_read(3)) {
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 $s->sysread($buf, 1024);
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 };
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 log_in($buf);
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 return $buf;
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 }
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135
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 sub stream_daemon {
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139 my $server = IO::Socket::INET->new(
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 Proto => 'tcp',
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141 LocalHost => '127.0.0.1:8089',
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142 Listen => 5,
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 Reuse => 1
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 or die "Can't create listening socket: $!\n";
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 local $SIG{PIPE} = 'IGNORE';
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 while (my $client = $server->accept()) {
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150 $client->autoflush(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 log2c("(new connection $client)");
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 $client->sysread(my $buffer, 65536) or next;
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 log2i("$client $buffer");
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 $buffer = 'SEE-THIS';
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 log2o("$client $buffer");
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 $client->syswrite($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 } continue {
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
165 close $client;
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 }
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 sub log2i { Test::Nginx::log_core('|| <<', @_); }
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170 sub log2o { Test::Nginx::log_core('|| >>', @_); }
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 sub log2c { Test::Nginx::log_core('||', @_); }
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173 ###############################################################################