Mercurial > hg > nginx-tests
annotate stream_split_clients.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 |
---|---|
979
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream split_client module. |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::Stream qw/ stream /; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream stream_split_clients stream_return/); |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 $t->write_file_expand('nginx.conf', <<'EOF'); |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 daemon off; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 events { |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 } |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1251
diff
changeset
|
38 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1251
diff
changeset
|
39 |
979
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 split_clients $connection $variant { |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 51.2% "first"; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 10% "second"; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 * "third"; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 } |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server { |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 listen 127.0.0.1:8080; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 return $variant; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 } |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 EOF |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1235
diff
changeset
|
54 $t->run(); |
979
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 $t->plan(1); |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 ############################################################################### |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 # NB: split_clients distribution is a subject to implementation details |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 like(many('/', 20), qr/first: 12, second: 2, third: 6/, 'split'); |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 ############################################################################### |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 sub many { |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 my ($uri, $count) = @_; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 my %dist; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 for (1 .. $count) { |
1235
3fc6817cd84a
Tests: explicit peer port in stream tests now required.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
979
diff
changeset
|
70 if (my $data = stream('127.0.0.1:' . port(8080))->read()) { |
979
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 $dist{$data} = 0 unless defined $data; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 $dist{$data}++; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 } |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 } |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 return join ', ', map { $_ . ": " . $dist{$_} } sort keys %dist; |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 } |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
ef6be3201851
Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 ############################################################################### |