annotate stream_proxy_next_upstream.t @ 1609:f3ba4c74de31

Tests: added TEST_GLOBALS_STREAM variable support.
author Andrei Belov <defan@nginx.com>
date Thu, 12 Nov 2020 17:46:49 +0300
parents 76090a5da00b
children da1325cb1c39
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 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 {
1609
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1505
diff changeset
38 %%TEST_GLOBALS_STREAM%%
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1505
diff changeset
39
553
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 upstream u {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
41 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
42 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
43 server 127.0.0.1:8085 backup;
553
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
572
ca54b445d982 Tests: masked nginx bug in proxy next upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents: 565
diff changeset
46 upstream u2 {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
47 server 127.0.0.1:8083;
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
48 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
49 }
ca54b445d982 Tests: masked nginx bug in proxy next upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents: 565
diff changeset
50
1505
76090a5da00b Tests: unbreak various tests with TCP blackhole.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1468
diff changeset
51 proxy_connect_timeout 2;
76090a5da00b Tests: unbreak various tests with TCP blackhole.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1468
diff changeset
52
553
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
54 listen 127.0.0.1:8080;
553
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 off;
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 {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
60 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
61 proxy_pass u2;
553
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 }
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 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
66 listen 127.0.0.1:8082;
553
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 proxy_pass u;
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 proxy_next_upstream on;
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 proxy_next_upstream_tries 2;
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
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 EOF
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 $t->run_daemon(\&stream_daemon);
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
76 $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
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
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
80 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
81 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
82
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 # make sure backup is not tried
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
85 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
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
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 sub stream_daemon {
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 my $server = IO::Socket::INET->new(
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 Proto => 'tcp',
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
92 LocalHost => '127.0.0.1:' . port(8085),
553
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 Listen => 5,
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 Reuse => 1
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 or die "Can't create listening socket: $!\n";
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 local $SIG{PIPE} = 'IGNORE';
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 while (my $client = $server->accept()) {
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 $client->autoflush(1);
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 log2c("(new connection $client)");
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 $client->sysread(my $buffer, 65536) or next;
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 log2i("$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 $buffer = 'SEE-THIS';
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 log2o("$client $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 $client->syswrite($buffer);
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 } continue {
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 close $client;
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 }
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 sub log2i { Test::Nginx::log_core('|| <<', @_); }
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 sub log2o { Test::Nginx::log_core('|| >>', @_); }
e47cd1b95997 Tests: stream tests for proxy_next_upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 sub log2c { Test::Nginx::log_core('||', @_); }
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 ###############################################################################