Mercurial > hg > nginx-tests
annotate stream_proxy_next_upstream.t @ 1468:875967f737d4
Tests: removed now unused timeout adjustments in stream tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 24 Apr 2019 14:49:05 +0300 |
parents | 882267679006 |
children | 76090a5da00b |
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 BEGIN { use FindBin; chdir($FindBin::Bin); } |
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 use lib 'lib'; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
572
diff
changeset
|
19 use Test::Nginx::Stream qw/ stream /; |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
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 select STDERR; $| = 1; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
554
4cc65166509e
Tests: removed superfluous try_run() check.
Sergey Kandaurov <pluknet@nginx.com>
parents:
553
diff
changeset
|
26 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
|
27 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 $t->write_file_expand('nginx.conf', <<'EOF'); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 daemon off; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 events { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 } |
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 stream { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 upstream u { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
39 server 127.0.0.1:8083 max_fails=0; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
40 server 127.0.0.1:8084 max_fails=0; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
41 server 127.0.0.1:8085 backup; |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
572
ca54b445d982
Tests: masked nginx bug in proxy next upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
44 upstream u2 { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 server 127.0.0.1:8083; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
46 server 127.0.0.1:8085 backup; |
572
ca54b445d982
Tests: masked nginx bug in proxy next upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
47 } |
ca54b445d982
Tests: masked nginx bug in proxy next upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
48 |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
50 listen 127.0.0.1:8080; |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 proxy_pass u; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 proxy_next_upstream off; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
56 listen 127.0.0.1:8081; |
572
ca54b445d982
Tests: masked nginx bug in proxy next upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
57 proxy_pass u2; |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 proxy_next_upstream on; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
62 listen 127.0.0.1:8082; |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 proxy_pass u; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 proxy_next_upstream on; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 proxy_next_upstream_tries 2; |
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 } |
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 EOF |
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 $t->run_daemon(\&stream_daemon); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
72 $t->run()->waitforsocket('127.0.0.1:' . port(8085)); |
553
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 ############################################################################### |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
76 is(stream('127.0.0.1:' . port(8080))->io('.'), '', 'next off'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
77 is(stream('127.0.0.1:' . port(8081))->io('.'), 'SEE-THIS', 'next on'); |
553
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 # make sure backup is not tried |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
81 is(stream('127.0.0.1:' . port(8082))->io('.'), '', 'next tries'); |
553
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 ############################################################################### |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 sub stream_daemon { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 my $server = IO::Socket::INET->new( |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
88 LocalHost => '127.0.0.1:' . port(8085), |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 Listen => 5, |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 Reuse => 1 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 ) |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 or die "Can't create listening socket: $!\n"; |
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 local $SIG{PIPE} = 'IGNORE'; |
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 while (my $client = $server->accept()) { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 $client->autoflush(1); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 log2c("(new connection $client)"); |
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 $client->sysread(my $buffer, 65536) or next; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 log2i("$client $buffer"); |
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 $buffer = 'SEE-THIS'; |
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 log2o("$client $buffer"); |
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 $client->syswrite($buffer); |
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 } continue { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 close $client; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 } |
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 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 sub log2c { Test::Nginx::log_core('||', @_); } |
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 ############################################################################### |