Mercurial > hg > nginx-tests
annotate range.t @ 251:df984d23f9d1
Tests: improve fastcgi keepalive tests.
On some platforms fastcgi_keepalive.t tests failed due to problems in
handling of data split into multiple packets. Harden tests to fail
on all platforms by adding more sleeps, and mark them as TODO till
underlying problems are fixed.
Additionally, add some padding testing.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 25 Jan 2013 20:53:53 +0400 |
parents | 6a0d934950bc |
children | b6d566531746 |
rev | line source |
---|---|
33 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for range filter module. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
170
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http charset/)->plan(31); |
33 | 25 |
26 $t->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
28 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
29 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
179
diff
changeset
|
30 daemon off; |
33 | 31 |
32 events { | |
33 } | |
34 | |
35 http { | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
35
7bf0e8a1d66c
Tests: always define temp paths.
Maxim Dounin <mdounin@mdounin.ru>
parents:
33
diff
changeset
|
37 |
33 | 38 charset_map B A { |
39 58 59; # X -> Y | |
40 } | |
41 | |
42 server { | |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
35
diff
changeset
|
43 listen 127.0.0.1:8080; |
33 | 44 server_name localhost; |
45 | |
46 location /t2.html { | |
47 charset A; | |
48 source_charset B; | |
49 } | |
50 } | |
51 } | |
52 | |
53 EOF | |
54 | |
55 $t->write_file('t1.html', | |
56 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); | |
57 $t->write_file('t2.html', | |
58 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); | |
59 $t->run(); | |
60 | |
61 ############################################################################### | |
62 | |
63 my $t1; | |
64 | |
65 $t1 = http_get_range('/t1.html', 'Range: bytes=0-8'); | |
66 like($t1, qr/206/, 'range request - 206 partial reply'); | |
67 like($t1, qr/Content-Length: 9/, 'range request - correct length'); | |
68 like($t1, qr/Content-Range: bytes 0-8\/1000/, 'range request - content range'); | |
69 like($t1, qr/^X000XXXXX$/m, 'range request - correct content'); | |
70 | |
71 $t1 = http_get_range('/t1.html', 'Range: bytes=-10'); | |
72 like($t1, qr/206/, 'final bytes - 206 partial reply'); | |
73 like($t1, qr/Content-Length: 10/, 'final bytes - content length'); | |
74 like($t1, qr/Content-Range: bytes 990-999\/1000/, | |
75 'final bytes - content range'); | |
76 like($t1, qr/^X099XXXXXX$/m, 'final bytes - correct content'); | |
77 | |
78 $t1 = http_get_range('/t1.html', 'Range: bytes=990-'); | |
79 like($t1, qr/206/, 'final bytes explicit - 206 partial reply'); | |
80 like($t1, qr/Content-Length: 10/, 'final bytes explicit - content length'); | |
81 like($t1, qr/Content-Range: bytes 990-999\/1000/, | |
82 'final bytes explicit - content range'); | |
83 like($t1, qr/^X099XXXXXX$/m, 'final bytes explicit - correct content'); | |
84 | |
85 $t1 = http_get_range('/t1.html', 'Range: bytes=990-1990'); | |
86 like($t1, qr/206/, 'more than length - 206 partial reply'); | |
87 like($t1, qr/Content-Length: 10/, 'more than length - content length'); | |
88 like($t1, qr/Content-Range: bytes 990-999\/1000/, | |
89 'more than length - content range'); | |
90 like($t1, qr/^X099XXXXXX$/m, 'more than length - correct content'); | |
91 | |
92 $t1 = http_get_range('/t2.html', 'Range: bytes=990-1990'); | |
93 like($t1, qr/206/, 'recoded - 206 partial reply'); | |
94 like($t1, qr/Content-Length: 10/, 'recoded - content length'); | |
95 like($t1, qr/Content-Range: bytes 990-999\/1000/, 'recoded - content range'); | |
96 like($t1, qr/^Y099YYYYYY$/m, 'recoded - correct content'); | |
97 | |
98 $t1 = http_get_range('/t1.html', 'Range: bytes=0-9, -10, 10-19'); | |
99 like($t1, qr/206/, 'multipart - 206 partial reply'); | |
100 like($t1, qr/Content-Type: multipart\/byteranges; boundary=/, | |
101 'multipart - content type'); | |
102 like($t1, qr/X000XXXXXX/m, 'multipart - content 0-9'); | |
103 like($t1, qr/^X099XXXXXX\x0d?$/m, 'multipart - content -10 aka 990-999'); | |
104 like($t1, qr/X001XXXXXX\x0d?$/m, 'multipart - content 10-19'); | |
105 | |
170
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
106 $t1 = http_get_range('/t1.html', 'Range: bytes=0-9, -10, 100000-, 10-19'); |
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
107 like($t1, qr/206/, 'multipart big - 206 partial reply'); |
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
108 like($t1, qr/Content-Type: multipart\/byteranges; boundary=/, |
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
109 'multipart big - content type'); |
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
110 like($t1, qr/X000XXXXXX/m, 'multipart big - content 0-9'); |
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
111 like($t1, qr/^X099XXXXXX\x0d?$/m, 'multipart big - content -10 aka 990-999'); |
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
112 like($t1, qr/X001XXXXXX\x0d?$/m, 'multipart big - content 10-19'); |
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
113 |
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
114 like(http_get_range('/t1.html', 'Range: bytes=100000-'), qr/416/, |
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
115 'not satisfiable'); |
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
116 |
33 | 117 ############################################################################### |
118 | |
119 sub http_get_range { | |
120 my ($url, $extra) = @_; | |
121 return http(<<EOF); | |
122 GET $url HTTP/1.1 | |
123 Host: localhost | |
124 Connection: close | |
125 $extra | |
126 | |
127 EOF | |
128 } | |
129 | |
130 ############################################################################### |