Mercurial > hg > nginx-tests
annotate stream_proxy_next_upstream.t @ 1248:70192b1baf01
Tests: added exception test to stream_js.t using 'require'.
The stream js tests introduced in edf5a3c9e36a fail on njs 0.1.14. It doesn't
currently provide an easy way to check its version, whilst we are obligated to
gracefully handle such cases somehow. With such an addition of 'require', now
the tests are skipped instead on the previous versions.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 21 Nov 2017 13:16:39 +0300 |
parents | 882267679006 |
children | 875967f737d4 |
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 |
561
cd3e32d9997e
Tests: adjusted stream test timeouts, visible on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
554
diff
changeset
|
49 proxy_connect_timeout 1s; |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
52 listen 127.0.0.1:8080; |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 proxy_pass u; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 proxy_next_upstream off; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 } |
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 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
58 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
|
59 proxy_pass u2; |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 proxy_next_upstream on; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 } |
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 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
64 listen 127.0.0.1:8082; |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 proxy_pass u; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 proxy_next_upstream on; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 proxy_next_upstream_tries 2; |
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 } |
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 EOF |
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 $t->run_daemon(\&stream_daemon); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
74 $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
|
75 |
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 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
78 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
|
79 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
|
80 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 # make sure backup is not tried |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
83 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
|
84 |
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 sub stream_daemon { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 my $server = IO::Socket::INET->new( |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
90 LocalHost => '127.0.0.1:' . port(8085), |
553
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 Listen => 5, |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 Reuse => 1 |
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 or die "Can't create listening socket: $!\n"; |
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 local $SIG{PIPE} = 'IGNORE'; |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 while (my $client = $server->accept()) { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 $client->autoflush(1); |
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 log2c("(new connection $client)"); |
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 $client->sysread(my $buffer, 65536) or next; |
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 log2i("$client $buffer"); |
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 $buffer = 'SEE-THIS'; |
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 log2o("$client $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 $client->syswrite($buffer); |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 } continue { |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 close $client; |
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 } |
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 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
e47cd1b95997
Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 sub log2c { Test::Nginx::log_core('||', @_); } |
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 ############################################################################### |