Mercurial > hg > nginx-tests
annotate stream_upstream_least_conn.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 |
---|---|
557
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Stream tests for upstream least_conn balancer module. |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 use IO::Select; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
805
diff
changeset
|
21 use Test::Nginx::Stream qw/ stream /; |
557
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 ############################################################################### |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDERR; $| = 1; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/stream stream_upstream_least_conn/)->plan(2) |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 ->write_file_expand('nginx.conf', <<'EOF'); |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
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:
1235
diff
changeset
|
39 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1235
diff
changeset
|
40 |
557
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 upstream u { |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 least_conn; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 server 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
44 server 127.0.0.1:8082; |
557
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
48 listen 127.0.0.1:8080; |
557
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 proxy_pass u; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 EOF |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
55 $t->run_daemon(\&stream_daemon, port(8081)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
56 $t->run_daemon(\&stream_daemon, port(8082)); |
557
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 $t->run(); |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
59 $t->waitforsocket('127.0.0.1:' . port(8081)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
60 $t->waitforsocket('127.0.0.1:' . port(8082)); |
557
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 ############################################################################### |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
64 my @ports = my ($port1, $port2) = (port(8081), port(8082)); |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
65 |
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
66 is(many(10), "$port1: 5, $port2: 5", 'balanced'); |
566
4296379213c8
Tests: refactored stream least_conn tests similar to e4ff43e00d84.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
67 |
4296379213c8
Tests: refactored stream least_conn tests similar to e4ff43e00d84.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
68 my @sockets; |
4296379213c8
Tests: refactored stream least_conn tests similar to e4ff43e00d84.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
69 for (1 .. 2) { |
1235
3fc6817cd84a
Tests: explicit peer port in stream tests now required.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
70 my $s = stream('127.0.0.1:' . port(8080)); |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
805
diff
changeset
|
71 $s->write('w'); |
566
4296379213c8
Tests: refactored stream least_conn tests similar to e4ff43e00d84.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
72 push @sockets, $s; |
4296379213c8
Tests: refactored stream least_conn tests similar to e4ff43e00d84.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
73 } |
4296379213c8
Tests: refactored stream least_conn tests similar to e4ff43e00d84.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
74 |
4296379213c8
Tests: refactored stream least_conn tests similar to e4ff43e00d84.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
75 select undef, undef, undef, 0.2; |
4296379213c8
Tests: refactored stream least_conn tests similar to e4ff43e00d84.
Sergey Kandaurov <pluknet@nginx.com>
parents:
565
diff
changeset
|
76 |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
77 is(many(10), "$port2: 10", 'least_conn'); |
557
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 ############################################################################### |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 sub many { |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
82 my ($count) = @_; |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
805
diff
changeset
|
83 my (%ports); |
557
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 for (1 .. $count) { |
1235
3fc6817cd84a
Tests: explicit peer port in stream tests now required.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
86 if (stream('127.0.0.1:' . port(8080))->io('.') =~ /(\d+)/) { |
557
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 $ports{$1} = 0 unless defined $ports{$1}; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 $ports{$1}++; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
92 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
|
93 return join ', ', map { $_ . ": " . $ports{$_} } @keys; |
557
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 ############################################################################### |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 sub stream_daemon { |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 my ($port) = @_; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 my $server = IO::Socket::INET->new( |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 Proto => 'tcp', |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 LocalAddr => '127.0.0.1', |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 LocalPort => $port, |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 Listen => 5, |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 Reuse => 1 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 ) |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 or die "Can't create listening socket: $!\n"; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 my $sel = IO::Select->new($server); |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 local $SIG{PIPE} = 'IGNORE'; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 while (my @ready = $sel->can_read) { |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 foreach my $fh (@ready) { |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 if ($server == $fh) { |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 my $new = $fh->accept; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 $new->autoflush(1); |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 $sel->add($new); |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 } elsif (stream_handle_client($fh)) { |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 $sel->remove($fh); |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 $fh->close; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 sub stream_handle_client { |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 my ($client) = @_; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 log2c("(new connection $client)"); |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 $client->sysread(my $buffer, 65536) or return 1; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 log2i("$client $buffer"); |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 my $port = $client->sockport(); |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
140 if ($buffer =~ /w/ && $port == port(8081)) { |
557
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 Test::Nginx::log_core('||', "$port: sleep(2.5)"); |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 select undef, undef, undef, 2.5; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 $buffer = $port; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 log2o("$client $buffer"); |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 $client->syswrite($buffer); |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 return 1; |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 sub log2c { Test::Nginx::log_core('||', @_); } |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 |
05cbe9e2def8
Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 ############################################################################### |