Mercurial > hg > nginx-tests
annotate stream_limit_rate2.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 5ac6efbe5552 |
children |
rev | line source |
---|---|
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
1473
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
6 # Tests for stream proxy module, limit rate directives, variables support. |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 use IO::Select; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
21 use Test::Nginx::Stream qw/ stream /; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 ############################################################################### |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
25 select STDERR; $| = 1; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 |
1473
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/stream stream_map/) |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 ->write_file_expand('nginx.conf', <<'EOF'); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 events { |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1473
diff
changeset
|
39 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1473
diff
changeset
|
40 |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
41 # download and upload rates are set equal to the maximum |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 # number of bytes transmitted |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
43 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 # proxy_download_rate value comes from following calculations: |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 # test string length (1000) + whitespace (1) + time string length (10) |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 |
1473
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
47 map $server_port $down { |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
48 default 1011; |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
49 %%PORT_8082%% 0; |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
50 %%PORT_8083%% 1; |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
51 %%PORT_8085%% 250; |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
52 } |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
53 |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
54 map $server_port $up { |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
55 default 1000; |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
56 %%PORT_8082%% 0; |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
57 %%PORT_8084%% 1; |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
58 %%PORT_8086%% 250; |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
59 } |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
60 |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
61 proxy_download_rate $down; |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
62 proxy_upload_rate $up; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
65 listen 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
66 proxy_pass 127.0.0.1:8080; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
70 listen 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
71 proxy_pass 127.0.0.1:8080; |
1473
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
72 proxy_download_rate $down; |
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
73 proxy_upload_rate $up; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
77 listen 127.0.0.1:8083; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
78 proxy_pass 127.0.0.1:8080; |
1473
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
79 proxy_download_rate $down; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
80 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
82 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
83 listen 127.0.0.1:8084; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
84 proxy_pass 127.0.0.1:8080; |
1473
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
85 proxy_upload_rate $up; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
89 listen 127.0.0.1:8085; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
90 proxy_pass 127.0.0.1:8080; |
1473
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
91 proxy_download_rate $down; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
92 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
93 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
94 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
95 listen 127.0.0.1:8086; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
96 proxy_pass 127.0.0.1:8087; |
1473
ddbde6c5b0cd
Tests: stream limit rate tests, variables support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1472
diff
changeset
|
97 proxy_upload_rate $up; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
98 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
99 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
100 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
101 EOF |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
102 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
103 $t->run_daemon(\&stream_daemon, port(8080)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
104 $t->run_daemon(\&stream_daemon, port(8087)); |
1693
5ac6efbe5552
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1609
diff
changeset
|
105 $t->run()->plan(9); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
106 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
107 $t->waitforsocket('127.0.0.1:' . port(8080)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
108 $t->waitforsocket('127.0.0.1:' . port(8087)); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
109 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
110 ############################################################################### |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
111 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
112 my $str = '1234567890' x 100; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
113 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
114 my %r = response($str, peer => '127.0.0.1:' . port(8081)); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
115 is($r{'data'}, $str, 'exact limit'); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
116 |
1472
7ae2747ee593
Tests: more stream_limit_rate.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
117 %r = response($str . 'extra', peer => '127.0.0.1:' . port(8082)); |
7ae2747ee593
Tests: more stream_limit_rate.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
118 is($r{'data'}, $str . 'extra', 'unlimited'); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
119 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
120 SKIP: { |
1472
7ae2747ee593
Tests: more stream_limit_rate.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
121 skip 'unsafe on VM', 3 unless $ENV{TEST_NGINX_UNSAFE}; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
122 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
123 # if interaction between backend and client is slow then proxy can add extra |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
124 # bytes to upload/download data |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
125 |
1472
7ae2747ee593
Tests: more stream_limit_rate.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
126 %r = response($str . 'extra', peer => '127.0.0.1:' . port(8081)); |
7ae2747ee593
Tests: more stream_limit_rate.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
127 is($r{'data'}, $str, 'limited'); |
7ae2747ee593
Tests: more stream_limit_rate.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
128 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
129 %r = response($str, peer => '127.0.0.1:' . port(8083), readonce => 1); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
130 is($r{'data'}, '1', 'download - one byte'); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
131 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
132 %r = response($str, peer => '127.0.0.1:' . port(8084)); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
133 is($r{'data'}, '1', 'upload - one byte'); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
134 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
135 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
136 |
787
a53c310c695d
Tests: relaxed limit_rate tests timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
711
diff
changeset
|
137 # Five chunks are split with four 1s delays: |
710
aed139eaaf3f
Tests: fixed comment after 40675bfad7d3.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
637
diff
changeset
|
138 # the first four chunks are quarters of test string |
aed139eaaf3f
Tests: fixed comment after 40675bfad7d3.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
637
diff
changeset
|
139 # and the fifth one is some extra data from backend. |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
140 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
141 %r = response($str, peer => '127.0.0.1:' . port(8085)); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
142 my $diff = time() - $r{'time'}; |
787
a53c310c695d
Tests: relaxed limit_rate tests timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
711
diff
changeset
|
143 cmp_ok($diff, '>=', 4, 'download - time'); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
144 is($r{'data'}, $str, 'download - data'); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
145 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
146 my $time = time(); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
147 %r = response($str . 'close', peer => '127.0.0.1:' . port(8086)); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
148 $diff = time() - $time; |
787
a53c310c695d
Tests: relaxed limit_rate tests timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
711
diff
changeset
|
149 cmp_ok($diff, '>=', 4, 'upload - time'); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
150 is($r{'data'}, $str . 'close', 'upload - data'); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
151 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
152 ############################################################################### |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
153 |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
154 sub response { |
937
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
866
diff
changeset
|
155 my ($data, %extra) = @_; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
156 |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
157 my $s = stream($extra{peer}); |
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
158 $s->write($data); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
159 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
160 $data = ''; |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
161 while (1) { |
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
162 my $buf = $s->read(); |
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
163 last unless length($buf); |
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
164 |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
165 $data .= $buf; |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
166 |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
167 last if $extra{'readonce'}; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
168 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
169 $data =~ /([\S]*)\s?(\d+)?/; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
170 |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
171 return ('data' => $1, 'time' => $2) |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
172 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
173 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
174 ############################################################################### |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
175 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
176 sub stream_daemon { |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
177 my $port = shift; |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
937
diff
changeset
|
178 |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
179 my $server = IO::Socket::INET->new( |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
180 Proto => 'tcp', |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
181 LocalAddr => '127.0.0.1', |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
182 LocalPort => $port, |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
183 Listen => 5, |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
184 Reuse => 1 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
185 ) |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
186 or die "Can't create listening socket: $!\n"; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
187 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
188 my $sel = IO::Select->new($server); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
189 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
190 local $SIG{PIPE} = 'IGNORE'; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
191 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
192 while (my @ready = $sel->can_read) { |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
193 foreach my $fh (@ready) { |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
194 if ($server == $fh) { |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
195 my $new = $fh->accept; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
196 $new->autoflush(1); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
197 $sel->add($new); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
198 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
199 } elsif (stream_handle_client($fh)) { |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
200 $sel->remove($fh); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
201 $fh->close; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
202 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
203 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
204 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
205 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
206 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
207 sub stream_handle_client { |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
208 my ($client) = @_; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
209 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
210 log2c("(new connection $client)"); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
211 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
212 $client->sysread(my $buffer, 65536) or return 1; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
213 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
214 log2i("$client $buffer"); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
215 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
216 $buffer .= " " . time() if $client->sockport() eq port(8080); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
217 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
218 log2o("$client $buffer"); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
219 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
220 $client->syswrite($buffer); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
221 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
222 return $client->sockport() eq port(8080) ? 1 : $buffer =~ /close/; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
223 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
224 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
225 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
226 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
227 sub log2c { Test::Nginx::log_core('||', @_); } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
228 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
229 ############################################################################### |