Mercurial > hg > nginx-tests
annotate stream_upstream_hash.t @ 1571:1b4ceab9cb1c
Tests: fixed ssl_certificate.t with LibreSSL client.
Net::SSLeay::connect() that manages TLS handshake could return unexpected
error when receiving server alert, as seen in server certificate tests if
it could not been selected. Typically, it returns the expected error -1,
but with certain libssl implementations it can be 0, as explained below.
The error is propagated from libssl's SSL_connect(), which is usually -1.
In modern OpenSSL versions, it is the default error code used in the state
machine returned when something went wrong with parsing TLS message header.
In versions up to OpenSSL 1.0.2, with SSLv23_method() used by default, -1
is the only error code in the ssl_connect() method implementation which is
used as well if receiving alert while parsing ServerHello. BoringSSL also
seems to return -1. But it is not so with LibreSSL that returns zero.
Previously, tests failed with client built with LibreSSL with SSLv3 removed.
Here, the error is propagated directly from ssl_read_bytes() method, which
is always implemented as ssl3_read_bytes() in all TLS methods. It could be
also seen with OpenSSL up to 1.0.2 with non-default methods explicitly set.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 29 May 2020 23:10:20 +0300 |
parents | 06fbf6269f38 |
children | f3ba4c74de31 |
rev | line source |
---|---|
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Stream tests for upstream hash balancer module. |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 use IO::Select; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
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 /; |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 ############################################################################### |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDERR; $| = 1; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
1481
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/stream stream_upstream_hash/)->plan(4); |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 $t->write_file_expand('nginx.conf', <<'EOF'); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 daemon off; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 events { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 stream { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 upstream hash { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 hash $remote_addr; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
42 server 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 server 127.0.0.1:8083; |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 upstream cons { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 hash $remote_addr consistent; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
48 server 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
49 server 127.0.0.1:8083; |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
1481
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
52 upstream empty { |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
53 hash $proxy_protocol_addr; |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
54 server 127.0.0.1:8082; |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
55 server 127.0.0.1:8083; |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
56 } |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
57 |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
58 upstream cempty { |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
59 hash $proxy_protocol_addr consistent; |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
60 server 127.0.0.1:8082; |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
61 server 127.0.0.1:8083; |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
62 } |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
63 |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
65 listen 127.0.0.1:8080; |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 proxy_pass hash; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
70 listen 127.0.0.1:8081; |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 proxy_pass cons; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 } |
1481
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
73 |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
74 server { |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
75 listen 127.0.0.1:8084; |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
76 proxy_pass empty; |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
77 } |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
78 |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
79 server { |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
80 listen 127.0.0.1:8085; |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
81 proxy_pass cempty; |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
82 } |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 EOF |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
87 $t->run_daemon(\&stream_daemon, port(8082)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
88 $t->run_daemon(\&stream_daemon, port(8083)); |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 $t->run(); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
91 $t->waitforsocket('127.0.0.1:' . port(8082)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
92 $t->waitforsocket('127.0.0.1:' . port(8083)); |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 ############################################################################### |
5c3946ebd867
Tests: basic stream tests for upstream hash.
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 my @ports = my ($port2, $port3) = (port(8082), port(8083)); |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
97 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
98 is(many(10, port(8080)), "$port3: 10", 'hash'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
99 like(many(10, port(8081)), qr/($port2|$port3): 10/, 'hash consistent'); |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
1481
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
101 # fallback to round-robin |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
102 |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
103 TODO: { |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
104 local $TODO = 'not yet' unless $t->has_version('1.17.1'); |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
105 |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
106 like(many(4, port(8084)), qr/$port2: 2, $port3: 2/, 'empty key'); |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
107 like(many(4, port(8085)), qr/$port2: 2, $port3: 2/, 'empty key - consistent'); |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
108 |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
109 } |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
110 |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 ############################################################################### |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 sub many { |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
114 my ($count, $port) = @_; |
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
115 my (%ports); |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 for (1 .. $count) { |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
118 if (stream("127.0.0.1:$port")->io('.') =~ /(\d+)/) { |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 $ports{$1} = 0 unless defined $ports{$1}; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 $ports{$1}++; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
124 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
|
125 return join ', ', map { $_ . ": " . $ports{$_} } @keys; |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 ############################################################################### |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 sub stream_daemon { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 my ($port) = @_; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 my $server = IO::Socket::INET->new( |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 Proto => 'tcp', |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 LocalAddr => '127.0.0.1', |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 LocalPort => $port, |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 Listen => 5, |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 Reuse => 1 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 ) |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 or die "Can't create listening socket: $!\n"; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 my $sel = IO::Select->new($server); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 local $SIG{PIPE} = 'IGNORE'; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 while (my @ready = $sel->can_read) { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 foreach my $fh (@ready) { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 if ($server == $fh) { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 my $new = $fh->accept; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 $new->autoflush(1); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 $sel->add($new); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 } elsif (stream_handle_client($fh)) { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 $sel->remove($fh); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 $fh->close; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 sub stream_handle_client { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 my ($client) = @_; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 log2c("(new connection $client)"); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 $client->sysread(my $buffer, 65536) or return 1; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 log2i("$client $buffer"); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 $buffer = $client->sockport(); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 log2o("$client $buffer"); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 $client->syswrite($buffer); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 return 1; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 sub log2c { Test::Nginx::log_core('||', @_); } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 ############################################################################### |