Mercurial > hg > nginx-tests
comparison h2_limit_req.t @ 948:4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Stopped exporting any subroutines. A subset of them now act as class methods.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 17 Jun 2016 11:36:33 +0300 |
parents | ee4a4b42d65f |
children | 991ef7781b38 |
comparison
equal
deleted
inserted
replaced
947:b9e42c554ba7 | 948:4dc302d8e04f |
---|---|
14 | 14 |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | 15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
16 | 16 |
17 use lib 'lib'; | 17 use lib 'lib'; |
18 use Test::Nginx; | 18 use Test::Nginx; |
19 use Test::Nginx::HTTP2 qw/ :DEFAULT :frame /; | 19 use Test::Nginx::HTTP2; |
20 | 20 |
21 ############################################################################### | 21 ############################################################################### |
22 | 22 |
23 select STDERR; $| = 1; | 23 select STDERR; $| = 1; |
24 select STDOUT; $| = 1; | 24 select STDOUT; $| = 1; |
67 $t->write_file('index.html', ''); | 67 $t->write_file('index.html', ''); |
68 $t->write_file('t.html', 'SEE-THIS'); | 68 $t->write_file('t.html', 'SEE-THIS'); |
69 $t->run(); | 69 $t->run(); |
70 | 70 |
71 ############################################################################### | 71 ############################################################################### |
72 | 72 my $sess; |
73 # request body delayed in limit_req | 73 # request body delayed in limit_req |
74 | 74 |
75 my $sess = new_session(); | 75 my $s = Test::Nginx::HTTP2->new(); |
76 my $sid = new_stream($sess, { path => '/proxy_limit_req/', body_more => 1 }); | 76 my $sid = $s->new_stream({ path => '/proxy_limit_req/', body_more => 1 }); |
77 h2_body($sess, 'TEST'); | 77 $s->h2_body('TEST'); |
78 my $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | 78 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
79 | 79 |
80 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 80 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
81 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST', | 81 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST', |
82 'request body - limit req'); | 82 'request body - limit req'); |
83 | 83 |
84 TODO: { | 84 TODO: { |
85 local $TODO = 'not yet' unless $t->has_version('1.9.15'); | 85 local $TODO = 'not yet' unless $t->has_version('1.9.15'); |
86 | 86 |
87 $sess = new_session(); | 87 $s = Test::Nginx::HTTP2->new(); |
88 $sid = new_stream($sess, { path => '/proxy_limit_req/', body_more => 1 }); | 88 $sid = $s->new_stream({ path => '/proxy_limit_req/', body_more => 1 }); |
89 select undef, undef, undef, 1.1; | 89 select undef, undef, undef, 1.1; |
90 h2_body($sess, 'TEST'); | 90 $s->h2_body('TEST'); |
91 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | 91 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
92 | 92 |
93 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 93 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
94 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST', | 94 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST', |
95 'request body - limit req - limited'); | 95 'request body - limit req - limited'); |
96 | 96 |
97 } | 97 } |
98 | 98 |
99 # request body delayed in limit_req - with an empty DATA frame | 99 # request body delayed in limit_req - with an empty DATA frame |
100 # "zero size buf in output" alerts seen | 100 # "zero size buf in output" alerts seen |
101 | 101 |
102 $sess = new_session(); | 102 $s = Test::Nginx::HTTP2->new(); |
103 $sid = new_stream($sess, { path => '/proxy_limit_req/', body_more => 1 }); | 103 $sid = $s->new_stream({ path => '/proxy_limit_req/', body_more => 1 }); |
104 h2_body($sess, ''); | 104 $s->h2_body(''); |
105 select undef, undef, undef, 1.1; | 105 select undef, undef, undef, 1.1; |
106 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | 106 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
107 | 107 |
108 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 108 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
109 is($frame->{headers}->{':status'}, 200, 'request body - limit req - empty'); | 109 is($frame->{headers}->{':status'}, 200, 'request body - limit req - empty'); |
110 | 110 |
111 # predict send windows | 111 # predict send windows |
112 | 112 |
113 $sid = new_stream($sess); | 113 $sid = $s->new_stream(); |
114 my ($maxwin) = sort {$a <=> $b} $sess->{streams}{$sid}, $sess->{conn_window}; | 114 my ($maxwin) = sort {$a <=> $b} $s->{streams}{$sid}, $s->{conn_window}; |
115 | 115 |
116 SKIP: { | 116 SKIP: { |
117 skip 'leaves coredump', 1 unless $t->has_version('1.9.7'); | 117 skip 'leaves coredump', 1 unless $t->has_version('1.9.7'); |
118 skip 'not enough window', 1 if $maxwin < 5; | 118 skip 'not enough window', 1 if $maxwin < 5; |
119 | 119 |
120 $sess = new_session(); | 120 $s = Test::Nginx::HTTP2->new(); |
121 $sid = new_stream($sess, { path => '/proxy_limit_req/', body => 'TEST2' }); | 121 $sid = $s->new_stream({ path => '/proxy_limit_req/', body => 'TEST2' }); |
122 select undef, undef, undef, 1.1; | 122 select undef, undef, undef, 1.1; |
123 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | 123 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
124 | 124 |
125 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 125 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
126 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST2', | 126 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST2', |
127 'request body - limit req 2'); | 127 'request body - limit req 2'); |
128 | 128 |
129 } | 129 } |
130 | 130 |
131 # partial request body data frame received (to be discarded) within request | 131 # partial request body data frame received (to be discarded) within request |
132 # delayed in limit_req, the rest of data frame is received after response | 132 # delayed in limit_req, the rest of data frame is received after response |
133 | 133 |
134 $sess = new_session(); | 134 $s = Test::Nginx::HTTP2->new(); |
135 | 135 |
136 SKIP: { | 136 SKIP: { |
137 skip 'not enough window', 1 if $maxwin < 4; | 137 skip 'not enough window', 1 if $maxwin < 4; |
138 | 138 |
139 TODO: { | 139 TODO: { |
140 todo_skip 'use-after-free', 1 unless $ENV{TEST_NGINX_UNSAFE} | 140 todo_skip 'use-after-free', 1 unless $ENV{TEST_NGINX_UNSAFE} |
141 or $t->has_version('1.9.12'); | 141 or $t->has_version('1.9.12'); |
142 | 142 |
143 $sid = new_stream($sess, { path => '/limit_req', body => 'TEST', split => [61], | 143 $sid = $s->new_stream({ path => '/limit_req', body => 'TEST', split => [61], |
144 split_delay => 1.1 }); | 144 split_delay => 1.1 }); |
145 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | 145 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
146 | 146 |
147 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 147 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
148 is($frame->{headers}->{':status'}, '200', 'discard body - limit req - limited'); | 148 is($frame->{headers}->{':status'}, '200', 'discard body - limit req - limited'); |
149 | 149 |
150 } | 150 } |
151 | 151 |
152 } | 152 } |
153 | 153 |
154 $sid = new_stream($sess, { path => '/' }); | 154 $sid = $s->new_stream({ path => '/' }); |
155 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | 155 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
156 | 156 |
157 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 157 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
158 is($frame->{headers}->{':status'}, '200', 'discard body - limit req - next'); | 158 is($frame->{headers}->{':status'}, '200', 'discard body - limit req - next'); |
159 | 159 |
160 # ditto, but instead of receiving the rest of data frame, connection is closed | 160 # ditto, but instead of receiving the rest of data frame, connection is closed |
165 | 165 |
166 TODO: { | 166 TODO: { |
167 todo_skip 'use-after-free', 1 unless $ENV{TEST_NGINX_UNSAFE} | 167 todo_skip 'use-after-free', 1 unless $ENV{TEST_NGINX_UNSAFE} |
168 or $t->has_version('1.9.12'); | 168 or $t->has_version('1.9.12'); |
169 | 169 |
170 $sess = new_session(); | 170 $s = Test::Nginx::HTTP2->new(); |
171 $sid = new_stream($sess, { path => '/limit_req', body => 'TEST', split => [61], | 171 $sid = $s->new_stream({ path => '/limit_req', body => 'TEST', split => [61], |
172 abort => 1 }); | 172 abort => 1 }); |
173 | 173 |
174 select undef, undef, undef, 1.1; | 174 select undef, undef, undef, 1.1; |
175 close $sess->{socket}; | 175 close $s->{socket}; |
176 | 176 |
177 pass('discard body - limit req - eof'); | 177 pass('discard body - limit req - eof'); |
178 | 178 |
179 } | 179 } |
180 | 180 |