Mercurial > hg > nginx-tests
annotate stream_upstream.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | f3ba4c74de31 |
children |
rev | line source |
---|---|
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Stream tests for upstream module and balancers. |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 use IO::Select; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
711
diff
changeset
|
21 use Test::Nginx::Stream qw/ stream /; |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 ############################################################################### |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDERR; $| = 1; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
1026
e74a9342eb96
Tests: stream tests for per-upstream variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/stream/) |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 ->write_file_expand('nginx.conf', <<'EOF'); |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1505
diff
changeset
|
39 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1505
diff
changeset
|
40 |
1026
e74a9342eb96
Tests: stream tests for per-upstream variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
41 log_format bytes $upstream_addr! |
e74a9342eb96
Tests: stream tests for per-upstream variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
42 $upstream_bytes_sent!$upstream_bytes_received; |
e74a9342eb96
Tests: stream tests for per-upstream variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
43 |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 upstream u { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 server 127.0.0.1:8084; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
46 server 127.0.0.1:8085; |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 upstream u2 { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
50 server 127.0.0.1:8086 down; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
51 server 127.0.0.1:8086; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
52 server 127.0.0.1:8084; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
53 server 127.0.0.1:8085; |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 upstream u3 { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
57 server 127.0.0.1:8084; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
58 server 127.0.0.1:8085 weight=2; |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 upstream u4 { |
1105
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
62 server 127.0.0.1:8086 fail_timeout=1s; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
63 server 127.0.0.1:8084 backup; |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
1505
76090a5da00b
Tests: unbreak various tests with TCP blackhole.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1468
diff
changeset
|
66 proxy_connect_timeout 2; |
76090a5da00b
Tests: unbreak various tests with TCP blackhole.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1468
diff
changeset
|
67 |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
69 listen 127.0.0.1:8080; |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 proxy_pass u; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
74 listen 127.0.0.1:8081; |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 proxy_pass u2; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
79 listen 127.0.0.1:8082; |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 proxy_pass u3; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
84 listen 127.0.0.1:8083; |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 proxy_pass u4; |
1026
e74a9342eb96
Tests: stream tests for per-upstream variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
86 access_log %%TESTDIR%%/u.log bytes; |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 EOF |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
92 $t->run_daemon(\&stream_daemon, port(8084)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
93 $t->run_daemon(\&stream_daemon, port(8085)); |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1105
diff
changeset
|
94 $t->run()->plan(6); |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
96 $t->waitforsocket('127.0.0.1:' . port(8084)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
97 $t->waitforsocket('127.0.0.1:' . port(8085)); |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 ############################################################################### |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
1026
e74a9342eb96
Tests: stream tests for per-upstream variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
101 my @ports = my ($port4, $port5, $port6) = (port(8084), port(8085), port(8086)); |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
102 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
103 is(many(30, port(8080)), "$port4: 15, $port5: 15", 'balanced'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
104 is(many(30, port(8081)), "$port4: 15, $port5: 15", 'failures'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
105 is(many(30, port(8082)), "$port4: 10, $port5: 20", 'weight'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
106 is(many(30, port(8083)), "$port4: 30", 'backup'); |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 |
1105
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
108 $t->run_daemon(\&stream_daemon, port(8086)); |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
109 $t->waitforsocket('127.0.0.1:' . port(8086)); |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
110 |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
111 sleep 2; # wait till fail_timeout passes |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
112 is(parallel(30, port(8083)), "$port6: 30", 'recovery'); |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
113 |
1026
e74a9342eb96
Tests: stream tests for per-upstream variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
114 $t->stop(); |
e74a9342eb96
Tests: stream tests for per-upstream variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
115 |
e74a9342eb96
Tests: stream tests for per-upstream variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
116 like($t->read_file('u.log'), qr/127.0.0.1:$port6, 127.0.0.1:$port4!0, 1!0, 4/, |
e74a9342eb96
Tests: stream tests for per-upstream variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
117 'per-upstream variables'); |
e74a9342eb96
Tests: stream tests for per-upstream variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
118 |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 ############################################################################### |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 sub many { |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
122 my ($count, $port) = @_; |
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
123 my (%ports); |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 for (1 .. $count) { |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
126 if (stream("127.0.0.1:$port")->io('.') =~ /(\d+)/) { |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 $ports{$1} = 0 unless defined $ports{$1}; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 $ports{$1}++; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
132 my @keys = map { my $p = $_; grep { $p == $_ } keys %ports } @ports; |
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
133 return join ', ', map { $_ . ": " . $ports{$_} } @keys; |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 |
1105
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
136 sub parallel { |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
137 my ($count, $port) = @_; |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
138 my (%ports, @s); |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
139 |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
140 for (1 .. $count) { |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
141 my $s = stream("127.0.0.1:$port"); |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
142 $s->write('keep'); |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
143 $s->read(); |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
144 push @s, $s; |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
145 } |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
146 |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
147 for (1 .. $count) { |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
148 if ((pop @s)->io('.') =~ /(\d+)/) { |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
149 $ports{$1} = 0 unless defined $ports{$1}; |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
150 $ports{$1}++; |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
151 } |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
152 } |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
153 |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
154 my @keys = map { my $p = $_; grep { $p == $_ } keys %ports } @ports; |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
155 return join ', ', map { $_ . ": " . $ports{$_} } @keys; |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
156 } |
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
157 |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 ############################################################################### |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 sub stream_daemon { |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 my ($port) = @_; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 my $server = IO::Socket::INET->new( |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 Proto => 'tcp', |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 LocalAddr => '127.0.0.1', |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 LocalPort => $port, |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 Listen => 5, |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 Reuse => 1 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 ) |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 or die "Can't create listening socket: $!\n"; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 my $sel = IO::Select->new($server); |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 local $SIG{PIPE} = 'IGNORE'; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 while (my @ready = $sel->can_read) { |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 foreach my $fh (@ready) { |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 if ($server == $fh) { |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 my $new = $fh->accept; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 $new->autoflush(1); |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 $sel->add($new); |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 } elsif (stream_handle_client($fh)) { |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 $sel->remove($fh); |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 $fh->close; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 sub stream_handle_client { |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 my ($client) = @_; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 log2c("(new connection $client)"); |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 $client->sysread(my $buffer, 65536) or return 1; |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
198 log2i("$client $buffer"); |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 |
1105
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
200 my $close = $buffer ne 'keep'; |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 $buffer = $client->sockport(); |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 log2o("$client $buffer"); |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 $client->syswrite($buffer); |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 |
1105
a073a545413d
Tests: stream upstream tests for fast peer recovery.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1026
diff
changeset
|
207 return $close; |
556
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
208 } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
209 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
212 sub log2c { Test::Nginx::log_core('||', @_); } |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
213 |
97d89d9ab4ed
Tests: basic stream upstream tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
214 ############################################################################### |