Mercurial > hg > nginx-tests
annotate stream_limit_rate.t @ 1896:8b74936ff2ac
Tests: added has_feature() test for CryptX.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 29 May 2023 17:04:36 +0400 |
parents | f3ba4c74de31 |
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 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream proxy module, limit rate directives. |
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 |
1472
7ae2747ee593
Tests: more stream_limit_rate.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/stream/)->plan(9) |
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:
1472
diff
changeset
|
39 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1472
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 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 proxy_download_rate 1011; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 proxy_upload_rate 1000; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
51 listen 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
52 proxy_pass 127.0.0.1:8080; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
56 listen 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
57 proxy_pass 127.0.0.1:8080; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 proxy_download_rate 0; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 proxy_upload_rate 0; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
63 listen 127.0.0.1:8083; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
64 proxy_pass 127.0.0.1:8080; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 proxy_download_rate 1; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 } |
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 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
69 listen 127.0.0.1:8084; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
70 proxy_pass 127.0.0.1:8080; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 proxy_upload_rate 1; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
75 listen 127.0.0.1:8085; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
76 proxy_pass 127.0.0.1:8080; |
634
40675bfad7d3
Tests: fixed stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
632
diff
changeset
|
77 proxy_download_rate 250; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
80 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
81 listen 127.0.0.1:8086; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
82 proxy_pass 127.0.0.1:8087; |
634
40675bfad7d3
Tests: fixed stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
632
diff
changeset
|
83 proxy_upload_rate 250; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
84 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 } |
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 EOF |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@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(8080)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
90 $t->run_daemon(\&stream_daemon, port(8087)); |
866
5048b8f0fedd
Tests: removed try_run() checks for legacy versions.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
816
diff
changeset
|
91 $t->run(); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@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(8080)); |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
94 $t->waitforsocket('127.0.0.1:' . port(8087)); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
95 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
96 ############################################################################### |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
97 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
98 my $str = '1234567890' x 100; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
99 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
100 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
|
101 is($r{'data'}, $str, 'exact limit'); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
102 |
1472
7ae2747ee593
Tests: more stream_limit_rate.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
103 %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
|
104 is($r{'data'}, $str . 'extra', 'unlimited'); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
105 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
106 SKIP: { |
1472
7ae2747ee593
Tests: more stream_limit_rate.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
107 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
|
108 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
109 # 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
|
110 # bytes to upload/download data |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
111 |
1472
7ae2747ee593
Tests: more stream_limit_rate.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
112 %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
|
113 is($r{'data'}, $str, 'limited'); |
7ae2747ee593
Tests: more stream_limit_rate.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
114 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
115 %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
|
116 is($r{'data'}, '1', 'download - one byte'); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
117 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
118 %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
|
119 is($r{'data'}, '1', 'upload - one byte'); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
120 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
121 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
122 |
787
a53c310c695d
Tests: relaxed limit_rate tests timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
711
diff
changeset
|
123 # Five chunks are split with four 1s delays: |
710
aed139eaaf3f
Tests: fixed comment after 40675bfad7d3.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
637
diff
changeset
|
124 # the first four chunks are quarters of test string |
aed139eaaf3f
Tests: fixed comment after 40675bfad7d3.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
637
diff
changeset
|
125 # 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
|
126 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
127 %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
|
128 my $diff = time() - $r{'time'}; |
787
a53c310c695d
Tests: relaxed limit_rate tests timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
711
diff
changeset
|
129 cmp_ok($diff, '>=', 4, 'download - time'); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
130 is($r{'data'}, $str, 'download - data'); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
131 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
132 my $time = time(); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
133 %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
|
134 $diff = time() - $time; |
787
a53c310c695d
Tests: relaxed limit_rate tests timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
711
diff
changeset
|
135 cmp_ok($diff, '>=', 4, 'upload - time'); |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
136 is($r{'data'}, $str . 'close', 'upload - data'); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
137 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
138 ############################################################################### |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
139 |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
140 sub response { |
937
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
866
diff
changeset
|
141 my ($data, %extra) = @_; |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
142 |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
143 my $s = stream($extra{peer}); |
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
144 $s->write($data); |
632
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 $data = ''; |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
147 while (1) { |
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
148 my $buf = $s->read(); |
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
149 last unless length($buf); |
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
150 |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
151 $data .= $buf; |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
787
diff
changeset
|
152 |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
153 last if $extra{'readonce'}; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
154 } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
155 $data =~ /([\S]*)\s?(\d+)?/; |
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 return ('data' => $1, 'time' => $2) |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
158 } |
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 ############################################################################### |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
161 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
162 sub stream_daemon { |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
163 my $port = shift; |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
937
diff
changeset
|
164 |
632
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
165 my $server = IO::Socket::INET->new( |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
166 Proto => 'tcp', |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
167 LocalAddr => '127.0.0.1', |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
168 LocalPort => $port, |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
169 Listen => 5, |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
170 Reuse => 1 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
171 ) |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
172 or die "Can't create listening socket: $!\n"; |
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 my $sel = IO::Select->new($server); |
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 local $SIG{PIPE} = 'IGNORE'; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
177 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
178 while (my @ready = $sel->can_read) { |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
179 foreach my $fh (@ready) { |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
180 if ($server == $fh) { |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
181 my $new = $fh->accept; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
182 $new->autoflush(1); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
183 $sel->add($new); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
184 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
185 } elsif (stream_handle_client($fh)) { |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
186 $sel->remove($fh); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
187 $fh->close; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
188 } |
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 } |
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 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
193 sub stream_handle_client { |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
194 my ($client) = @_; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
195 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
196 log2c("(new connection $client)"); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
197 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
198 $client->sysread(my $buffer, 65536) or return 1; |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
199 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
200 log2i("$client $buffer"); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
201 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
202 $buffer .= " " . time() if $client->sockport() eq port(8080); |
632
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 log2o("$client $buffer"); |
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 $client->syswrite($buffer); |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
207 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
208 return $client->sockport() eq port(8080) ? 1 : $buffer =~ /close/; |
632
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 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
211 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
212 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
213 sub log2c { Test::Nginx::log_core('||', @_); } |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
214 |
c8d6f816e094
Tests: stream limit rate tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
215 ############################################################################### |