Mercurial > hg > nginx-tests
annotate stream_upstream_hash.t @ 1971:ab45ee8011df
Tests: guarded session ticket tests for old OpenSSL versions.
Much like SNI support, TLS session tickets are available starting with
OpenSSL 0.9.8f if TLS extensions support is explicitly configured, and
enabled by default since 0.9.8j. As such, SNI availability is checked
to ensure TLS extensions support is compiled in.
Additionally, the ssl_session_ticket_key.t tests for automatic ticket key
rotation, which uses session ticket key callback, as introduced in
OpenSSL 0.9.8h.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 06 May 2024 00:03:16 +0300 |
parents | 5ac6efbe5552 |
children |
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 { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1481
diff
changeset
|
40 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1481
diff
changeset
|
41 |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 upstream hash { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 hash $remote_addr; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
44 server 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 server 127.0.0.1:8083; |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 upstream cons { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 hash $remote_addr consistent; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
50 server 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
51 server 127.0.0.1:8083; |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
1481
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
54 upstream empty { |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 } |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
59 |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
60 upstream cempty { |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
61 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
|
62 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
|
63 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
|
64 } |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
65 |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
67 listen 127.0.0.1:8080; |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 proxy_pass hash; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
72 listen 127.0.0.1:8081; |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 proxy_pass cons; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 } |
1481
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
75 |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
76 server { |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
77 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
|
78 proxy_pass empty; |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
79 } |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
80 |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
81 server { |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
82 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
|
83 proxy_pass cempty; |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
84 } |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 EOF |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
89 $t->run_daemon(\&stream_daemon, port(8082)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
90 $t->run_daemon(\&stream_daemon, port(8083)); |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 $t->run(); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
93 $t->waitforsocket('127.0.0.1:' . port(8082)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
94 $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
|
95 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 ############################################################################### |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
98 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
|
99 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
100 is(many(10, port(8080)), "$port3: 10", 'hash'); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
101 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
|
102 |
1481
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
103 # 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
|
104 |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
105 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
|
106 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
|
107 |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 ############################################################################### |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 sub many { |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
111 my ($count, $port) = @_; |
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
112 my (%ports); |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 for (1 .. $count) { |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
115 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
|
116 $ports{$1} = 0 unless defined $ports{$1}; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 $ports{$1}++; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
121 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
|
122 return join ', ', map { $_ . ": " . $ports{$_} } @keys; |
571
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 ############################################################################### |
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 sub stream_daemon { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 my ($port) = @_; |
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 my $server = IO::Socket::INET->new( |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 Proto => 'tcp', |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 LocalAddr => '127.0.0.1', |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 LocalPort => $port, |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 Listen => 5, |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 Reuse => 1 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 ) |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 or die "Can't create listening socket: $!\n"; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 my $sel = IO::Select->new($server); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 local $SIG{PIPE} = 'IGNORE'; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 while (my @ready = $sel->can_read) { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 foreach my $fh (@ready) { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 if ($server == $fh) { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 my $new = $fh->accept; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 $new->autoflush(1); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 $sel->add($new); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 } elsif (stream_handle_client($fh)) { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 $sel->remove($fh); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 $fh->close; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 } |
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 sub stream_handle_client { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 my ($client) = @_; |
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 log2c("(new connection $client)"); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 $client->sysread(my $buffer, 65536) or return 1; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 log2i("$client $buffer"); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 $buffer = $client->sockport(); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 log2o("$client $buffer"); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 $client->syswrite($buffer); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 return 1; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 } |
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 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 sub log2c { Test::Nginx::log_core('||', @_); } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 ############################################################################### |