Mercurial > hg > nginx-tests
annotate stream_upstream_hash.t @ 1689:dbd19195df8a
Tests: adjusted mail_smtp.t "long pipelined" TODO.
Prior to fixed reading with fully filled buffer in 2851e4c7de03 (1.21.0),
test for long pipelined commands leads to connection close by nginx, which
can result in RST and no response seen by the client, notably on win32.
While here, cleaned up permitted smtp_auth methods in that particular server.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 24 May 2021 22:09:54 +0300 |
parents | f3ba4c74de31 |
children | 5ac6efbe5552 |
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 TODO: { |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
106 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
|
107 |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
108 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
|
109 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
|
110 |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
111 } |
06fbf6269f38
Tests: upstream hash tests for round-robin fallback on empty key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
112 |
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 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 sub many { |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
116 my ($count, $port) = @_; |
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
117 my (%ports); |
571
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 for (1 .. $count) { |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
120 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
|
121 $ports{$1} = 0 unless defined $ports{$1}; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 $ports{$1}++; |
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 |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
126 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
|
127 return join ', ', map { $_ . ": " . $ports{$_} } @keys; |
571
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 ############################################################################### |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 sub stream_daemon { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 my ($port) = @_; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 my $server = IO::Socket::INET->new( |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 Proto => 'tcp', |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 LocalAddr => '127.0.0.1', |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 LocalPort => $port, |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 Listen => 5, |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 Reuse => 1 |
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 or die "Can't create listening socket: $!\n"; |
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 my $sel = IO::Select->new($server); |
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 local $SIG{PIPE} = 'IGNORE'; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 while (my @ready = $sel->can_read) { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 foreach my $fh (@ready) { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 if ($server == $fh) { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 my $new = $fh->accept; |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 $new->autoflush(1); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 $sel->add($new); |
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 } elsif (stream_handle_client($fh)) { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 $sel->remove($fh); |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 $fh->close; |
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 } |
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 sub stream_handle_client { |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 my ($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 log2c("(new connection $client)"); |
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 $client->sysread(my $buffer, 65536) or return 1; |
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 log2i("$client $buffer"); |
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 $buffer = $client->sockport(); |
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 log2o("$client $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 $client->syswrite($buffer); |
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 return 1; |
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 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 sub log2c { Test::Nginx::log_core('||', @_); } |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 |
5c3946ebd867
Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 ############################################################################### |