comparison h2_priority.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 a6abbfed42c0
children e9064d691790
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;
55 55
56 ############################################################################### 56 ###############################################################################
57 57
58 # stream muliplexing + PRIORITY frames 58 # stream muliplexing + PRIORITY frames
59 59
60 my $sess = new_session(); 60 my $s = Test::Nginx::HTTP2->new();
61 my $sid = new_stream($sess, { path => '/t1.html' }); 61 my $sid = $s->new_stream({ path => '/t1.html' });
62 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); 62 $s->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
63 63
64 my $sid2 = new_stream($sess, { path => '/t2.html' }); 64 my $sid2 = $s->new_stream({ path => '/t2.html' });
65 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); 65 $s->read(all => [{ sid => $sid2, fin => 0x4 }]);
66 66
67 h2_priority($sess, 0, $sid); 67 $s->h2_priority(0, $sid);
68 h2_priority($sess, 255, $sid2); 68 $s->h2_priority(255, $sid2);
69 69
70 h2_window($sess, 2**17, $sid); 70 $s->h2_window(2**17, $sid);
71 h2_window($sess, 2**17, $sid2); 71 $s->h2_window(2**17, $sid2);
72 h2_window($sess, 2**17); 72 $s->h2_window(2**17);
73 73
74 my $frames = h2_read($sess, all => [ 74 my $frames = $s->read(all => [
75 { sid => $sid, fin => 1 }, 75 { sid => $sid, fin => 1 },
76 { sid => $sid2, fin => 1 } 76 { sid => $sid2, fin => 1 }
77 ]); 77 ]);
78 78
79 my @data = grep { $_->{type} eq "DATA" } @$frames; 79 my @data = grep { $_->{type} eq "DATA" } @$frames;
80 is(join(' ', map { $_->{sid} } @data), "$sid2 $sid", 'weight - PRIORITY 1'); 80 is(join(' ', map { $_->{sid} } @data), "$sid2 $sid", 'weight - PRIORITY 1');
81 81
82 # and vice versa 82 # and vice versa
83 83
84 $sess = new_session(); 84 $s = Test::Nginx::HTTP2->new();
85 $sid = new_stream($sess, { path => '/t1.html' }); 85 $sid = $s->new_stream({ path => '/t1.html' });
86 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); 86 $s->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
87 87
88 $sid2 = new_stream($sess, { path => '/t2.html' }); 88 $sid2 = $s->new_stream({ path => '/t2.html' });
89 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); 89 $s->read(all => [{ sid => $sid2, fin => 0x4 }]);
90 90
91 h2_priority($sess, 255, $sid); 91 $s->h2_priority(255, $sid);
92 h2_priority($sess, 0, $sid2); 92 $s->h2_priority(0, $sid2);
93 93
94 h2_window($sess, 2**17, $sid); 94 $s->h2_window(2**17, $sid);
95 h2_window($sess, 2**17, $sid2); 95 $s->h2_window(2**17, $sid2);
96 h2_window($sess, 2**17); 96 $s->h2_window(2**17);
97 97
98 $frames = h2_read($sess, all => [ 98 $frames = $s->read(all => [
99 { sid => $sid, fin => 1 }, 99 { sid => $sid, fin => 1 },
100 { sid => $sid2, fin => 1 } 100 { sid => $sid2, fin => 1 }
101 ]); 101 ]);
102 102
103 @data = grep { $_->{type} eq "DATA" } @$frames; 103 @data = grep { $_->{type} eq "DATA" } @$frames;
104 is(join(' ', map { $_->{sid} } @data), "$sid $sid2", 'weight - PRIORITY 2'); 104 is(join(' ', map { $_->{sid} } @data), "$sid $sid2", 'weight - PRIORITY 2');
105 105
106 # stream muliplexing + HEADERS PRIORITY flag 106 # stream muliplexing + HEADERS PRIORITY flag
107 107
108 $sess = new_session(); 108 $s = Test::Nginx::HTTP2->new();
109 $sid = new_stream($sess, { path => '/t1.html', prio => 0 }); 109 $sid = $s->new_stream({ path => '/t1.html', prio => 0 });
110 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); 110 $s->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
111 111
112 $sid2 = new_stream($sess, { path => '/t2.html', prio => 255 }); 112 $sid2 = $s->new_stream({ path => '/t2.html', prio => 255 });
113 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); 113 $s->read(all => [{ sid => $sid2, fin => 0x4 }]);
114 114
115 h2_window($sess, 2**17, $sid); 115 $s->h2_window(2**17, $sid);
116 h2_window($sess, 2**17, $sid2); 116 $s->h2_window(2**17, $sid2);
117 h2_window($sess, 2**17); 117 $s->h2_window(2**17);
118 118
119 $frames = h2_read($sess, all => [ 119 $frames = $s->read(all => [
120 { sid => $sid, fin => 1 }, 120 { sid => $sid, fin => 1 },
121 { sid => $sid2, fin => 1 } 121 { sid => $sid2, fin => 1 }
122 ]); 122 ]);
123 123
124 @data = grep { $_->{type} eq "DATA" } @$frames; 124 @data = grep { $_->{type} eq "DATA" } @$frames;
125 my $sids = join ' ', map { $_->{sid} } @data; 125 my $sids = join ' ', map { $_->{sid} } @data;
126 is($sids, "$sid2 $sid", 'weight - HEADERS PRIORITY 1'); 126 is($sids, "$sid2 $sid", 'weight - HEADERS PRIORITY 1');
127 127
128 # and vice versa 128 # and vice versa
129 129
130 $sess = new_session(); 130 $s = Test::Nginx::HTTP2->new();
131 $sid = new_stream($sess, { path => '/t1.html', prio => 255 }); 131 $sid = $s->new_stream({ path => '/t1.html', prio => 255 });
132 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); 132 $s->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
133 133
134 $sid2 = new_stream($sess, { path => '/t2.html', prio => 0 }); 134 $sid2 = $s->new_stream({ path => '/t2.html', prio => 0 });
135 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); 135 $s->read(all => [{ sid => $sid2, fin => 0x4 }]);
136 136
137 h2_window($sess, 2**17, $sid); 137 $s->h2_window(2**17, $sid);
138 h2_window($sess, 2**17, $sid2); 138 $s->h2_window(2**17, $sid2);
139 h2_window($sess, 2**17); 139 $s->h2_window(2**17);
140 140
141 $frames = h2_read($sess, all => [ 141 $frames = $s->read(all => [
142 { sid => $sid, fin => 1 }, 142 { sid => $sid, fin => 1 },
143 { sid => $sid2, fin => 1 } 143 { sid => $sid2, fin => 1 }
144 ]); 144 ]);
145 145
146 @data = grep { $_->{type} eq "DATA" } @$frames; 146 @data = grep { $_->{type} eq "DATA" } @$frames;
149 149
150 # 5.3.1. Stream Dependencies 150 # 5.3.1. Stream Dependencies
151 151
152 # PRIORITY frame 152 # PRIORITY frame
153 153
154 $sess = new_session(); 154 $s = Test::Nginx::HTTP2->new();
155 155
156 h2_priority($sess, 16, 3, 0); 156 $s->h2_priority(16, 3, 0);
157 h2_priority($sess, 16, 1, 3); 157 $s->h2_priority(16, 1, 3);
158 158
159 $sid = new_stream($sess, { path => '/t1.html' }); 159 $sid = $s->new_stream({ path => '/t1.html' });
160 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); 160 $s->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
161 161
162 $sid2 = new_stream($sess, { path => '/t2.html' }); 162 $sid2 = $s->new_stream({ path => '/t2.html' });
163 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); 163 $s->read(all => [{ sid => $sid2, fin => 0x4 }]);
164 164
165 h2_window($sess, 2**17, $sid); 165 $s->h2_window(2**17, $sid);
166 h2_window($sess, 2**17, $sid2); 166 $s->h2_window(2**17, $sid2);
167 h2_window($sess, 2**17); 167 $s->h2_window(2**17);
168 168
169 $frames = h2_read($sess, all => [ 169 $frames = $s->read(all => [
170 { sid => $sid, fin => 1 }, 170 { sid => $sid, fin => 1 },
171 { sid => $sid2, fin => 1 }, 171 { sid => $sid2, fin => 1 },
172 ]); 172 ]);
173 173
174 @data = grep { $_->{type} eq "DATA" } @$frames; 174 @data = grep { $_->{type} eq "DATA" } @$frames;
175 $sids = join ' ', map { $_->{sid} } @data; 175 $sids = join ' ', map { $_->{sid} } @data;
176 is($sids, "$sid2 $sid", 'dependency - PRIORITY 1'); 176 is($sids, "$sid2 $sid", 'dependency - PRIORITY 1');
177 177
178 # and vice versa 178 # and vice versa
179 179
180 $sess = new_session(); 180 $s = Test::Nginx::HTTP2->new();
181 181
182 h2_priority($sess, 16, 1, 0); 182 $s->h2_priority(16, 1, 0);
183 h2_priority($sess, 16, 3, 1); 183 $s->h2_priority(16, 3, 1);
184 184
185 $sid = new_stream($sess, { path => '/t1.html' }); 185 $sid = $s->new_stream({ path => '/t1.html' });
186 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); 186 $s->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
187 187
188 $sid2 = new_stream($sess, { path => '/t2.html' }); 188 $sid2 = $s->new_stream({ path => '/t2.html' });
189 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); 189 $s->read(all => [{ sid => $sid2, fin => 0x4 }]);
190 190
191 h2_window($sess, 2**17, $sid); 191 $s->h2_window(2**17, $sid);
192 h2_window($sess, 2**17, $sid2); 192 $s->h2_window(2**17, $sid2);
193 h2_window($sess, 2**17); 193 $s->h2_window(2**17);
194 194
195 $frames = h2_read($sess, all => [ 195 $frames = $s->read(all => [
196 { sid => $sid, fin => 1 }, 196 { sid => $sid, fin => 1 },
197 { sid => $sid2, fin => 1 }, 197 { sid => $sid2, fin => 1 },
198 ]); 198 ]);
199 199
200 @data = grep { $_->{type} eq "DATA" } @$frames; 200 @data = grep { $_->{type} eq "DATA" } @$frames;
205 205
206 # 5.3.1. Stream Dependencies 206 # 5.3.1. Stream Dependencies
207 # A stream cannot depend on itself. An endpoint MUST treat this as a 207 # A stream cannot depend on itself. An endpoint MUST treat this as a
208 # stream error of type PROTOCOL_ERROR. 208 # stream error of type PROTOCOL_ERROR.
209 209
210 $sess = new_session(); 210 $s = Test::Nginx::HTTP2->new();
211 $sid = new_stream($sess); 211 $sid = $s->new_stream();
212 h2_read($sess, all => [{ sid => $sid, fin => 1 }]); 212 $s->read(all => [{ sid => $sid, fin => 1 }]);
213 213
214 h2_priority($sess, 0, $sid, $sid); 214 $s->h2_priority(0, $sid, $sid);
215 $frames = h2_read($sess, all => [{ type => 'RST_STREAM' }]); 215 $frames = $s->read(all => [{ type => 'RST_STREAM' }]);
216 216
217 my ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; 217 my ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames;
218 is($frame->{sid}, $sid, 'dependency - PRIORITY self - RST_STREAM'); 218 is($frame->{sid}, $sid, 'dependency - PRIORITY self - RST_STREAM');
219 is($frame->{code}, 1, 'dependency - PRIORITY self - PROTOCOL_ERROR'); 219 is($frame->{code}, 1, 'dependency - PRIORITY self - PROTOCOL_ERROR');
220 220
221 # HEADERS PRIORITY flag, reprioritize prior PRIORITY frame records 221 # HEADERS PRIORITY flag, reprioritize prior PRIORITY frame records
222 222
223 $sess = new_session(); 223 $s = Test::Nginx::HTTP2->new();
224 224
225 h2_priority($sess, 16, 1, 0); 225 $s->h2_priority(16, 1, 0);
226 h2_priority($sess, 16, 3, 0); 226 $s->h2_priority(16, 3, 0);
227 227
228 $sid = new_stream($sess, { path => '/t1.html', dep => 3 }); 228 $sid = $s->new_stream({ path => '/t1.html', dep => 3 });
229 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); 229 $s->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
230 230
231 $sid2 = new_stream($sess, { path => '/t2.html' }); 231 $sid2 = $s->new_stream({ path => '/t2.html' });
232 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); 232 $s->read(all => [{ sid => $sid2, fin => 0x4 }]);
233 233
234 h2_window($sess, 2**17, $sid); 234 $s->h2_window(2**17, $sid);
235 h2_window($sess, 2**17, $sid2); 235 $s->h2_window(2**17, $sid2);
236 h2_window($sess, 2**17); 236 $s->h2_window(2**17);
237 237
238 $frames = h2_read($sess, all => [ 238 $frames = $s->read(all => [
239 { sid => $sid, fin => 1 }, 239 { sid => $sid, fin => 1 },
240 { sid => $sid2, fin => 1 }, 240 { sid => $sid2, fin => 1 },
241 ]); 241 ]);
242 242
243 @data = grep { $_->{type} eq "DATA" } @$frames; 243 @data = grep { $_->{type} eq "DATA" } @$frames;
244 $sids = join ' ', map { $_->{sid} } @data; 244 $sids = join ' ', map { $_->{sid} } @data;
245 is($sids, "$sid2 $sid", 'dependency - HEADERS PRIORITY 1'); 245 is($sids, "$sid2 $sid", 'dependency - HEADERS PRIORITY 1');
246 246
247 # and vice versa 247 # and vice versa
248 248
249 $sess = new_session(); 249 $s = Test::Nginx::HTTP2->new();
250 250
251 h2_priority($sess, 16, 1, 0); 251 $s->h2_priority(16, 1, 0);
252 h2_priority($sess, 16, 3, 0); 252 $s->h2_priority(16, 3, 0);
253 253
254 $sid = new_stream($sess, { path => '/t1.html' }); 254 $sid = $s->new_stream({ path => '/t1.html' });
255 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); 255 $s->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
256 256
257 $sid2 = new_stream($sess, { path => '/t2.html', dep => 1 }); 257 $sid2 = $s->new_stream({ path => '/t2.html', dep => 1 });
258 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); 258 $s->read(all => [{ sid => $sid2, fin => 0x4 }]);
259 259
260 h2_window($sess, 2**17, $sid); 260 $s->h2_window(2**17, $sid);
261 h2_window($sess, 2**17, $sid2); 261 $s->h2_window(2**17, $sid2);
262 h2_window($sess, 2**17); 262 $s->h2_window(2**17);
263 263
264 $frames = h2_read($sess, all => [ 264 $frames = $s->read(all => [
265 { sid => $sid, fin => 1 }, 265 { sid => $sid, fin => 1 },
266 { sid => $sid2, fin => 1 }, 266 { sid => $sid2, fin => 1 },
267 ]); 267 ]);
268 268
269 @data = grep { $_->{type} eq "DATA" } @$frames; 269 @data = grep { $_->{type} eq "DATA" } @$frames;
270 $sids = join ' ', map { $_->{sid} } @data; 270 $sids = join ' ', map { $_->{sid} } @data;
271 is($sids, "$sid $sid2", 'dependency - HEADERS PRIORITY 2'); 271 is($sids, "$sid $sid2", 'dependency - HEADERS PRIORITY 2');
272 272
273 # HEADERS - self dependency 273 # HEADERS - self dependency
274 274
275 $sess = new_session(); 275 $s = Test::Nginx::HTTP2->new();
276 $sid = new_stream($sess, { dep => 1 }); 276 $sid = $s->new_stream({ dep => 1 });
277 $frames = h2_read($sess, all => [{ type => 'RST_STREAM' }]); 277 $frames = $s->read(all => [{ type => 'RST_STREAM' }]);
278 278
279 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; 279 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames;
280 is($frame->{sid}, $sid, 'dependency - HEADERS self - RST_STREAM'); 280 is($frame->{sid}, $sid, 'dependency - HEADERS self - RST_STREAM');
281 is($frame->{code}, 1, 'dependency - HEADERS self - PROTOCOL_ERROR'); 281 is($frame->{code}, 1, 'dependency - HEADERS self - PROTOCOL_ERROR');
282 282
283 # PRIORITY frame, weighted dependencies 283 # PRIORITY frame, weighted dependencies
284 284
285 $sess = new_session(); 285 $s = Test::Nginx::HTTP2->new();
286 286
287 h2_priority($sess, 16, 5, 0); 287 $s->h2_priority(16, 5, 0);
288 h2_priority($sess, 255, 1, 5); 288 $s->h2_priority(255, 1, 5);
289 h2_priority($sess, 0, 3, 5); 289 $s->h2_priority(0, 3, 5);
290 290
291 $sid = new_stream($sess, { path => '/t1.html' }); 291 $sid = $s->new_stream({ path => '/t1.html' });
292 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); 292 $s->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
293 293
294 $sid2 = new_stream($sess, { path => '/t2.html' }); 294 $sid2 = $s->new_stream({ path => '/t2.html' });
295 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); 295 $s->read(all => [{ sid => $sid2, fin => 0x4 }]);
296 296
297 my $sid3 = new_stream($sess, { path => '/t2.html' }); 297 my $sid3 = $s->new_stream({ path => '/t2.html' });
298 h2_read($sess, all => [{ sid => $sid3, fin => 0x4 }]); 298 $s->read(all => [{ sid => $sid3, fin => 0x4 }]);
299 299
300 h2_window($sess, 2**16, 1); 300 $s->h2_window(2**16, 1);
301 h2_window($sess, 2**16, 3); 301 $s->h2_window(2**16, 3);
302 h2_window($sess, 2**16, 5); 302 $s->h2_window(2**16, 5);
303 h2_window($sess, 2**16); 303 $s->h2_window(2**16);
304 304
305 $frames = h2_read($sess, all => [ 305 $frames = $s->read(all => [
306 { sid => $sid, fin => 1 }, 306 { sid => $sid, fin => 1 },
307 { sid => $sid2, fin => 1 }, 307 { sid => $sid2, fin => 1 },
308 { sid => $sid3, fin => 1 }, 308 { sid => $sid3, fin => 1 },
309 ]); 309 ]);
310 310
312 $sids = join ' ', map { $_->{sid} } @data; 312 $sids = join ' ', map { $_->{sid} } @data;
313 is($sids, "$sid3 $sid $sid2", 'weighted dependency - PRIORITY 1'); 313 is($sids, "$sid3 $sid $sid2", 'weighted dependency - PRIORITY 1');
314 314
315 # and vice versa 315 # and vice versa
316 316
317 $sess = new_session(); 317 $s = Test::Nginx::HTTP2->new();
318 318
319 h2_priority($sess, 16, 5, 0); 319 $s->h2_priority(16, 5, 0);
320 h2_priority($sess, 0, 1, 5); 320 $s->h2_priority(0, 1, 5);
321 h2_priority($sess, 255, 3, 5); 321 $s->h2_priority(255, 3, 5);
322 322
323 $sid = new_stream($sess, { path => '/t1.html' }); 323 $sid = $s->new_stream({ path => '/t1.html' });
324 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); 324 $s->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
325 325
326 $sid2 = new_stream($sess, { path => '/t2.html' }); 326 $sid2 = $s->new_stream({ path => '/t2.html' });
327 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); 327 $s->read(all => [{ sid => $sid2, fin => 0x4 }]);
328 328
329 $sid3 = new_stream($sess, { path => '/t2.html' }); 329 $sid3 = $s->new_stream({ path => '/t2.html' });
330 h2_read($sess, all => [{ sid => $sid3, fin => 0x4 }]); 330 $s->read(all => [{ sid => $sid3, fin => 0x4 }]);
331 331
332 h2_window($sess, 2**16, 1); 332 $s->h2_window(2**16, 1);
333 h2_window($sess, 2**16, 3); 333 $s->h2_window(2**16, 3);
334 h2_window($sess, 2**16, 5); 334 $s->h2_window(2**16, 5);
335 h2_window($sess, 2**16); 335 $s->h2_window(2**16);
336 336
337 $frames = h2_read($sess, all => [ 337 $frames = $s->read(all => [
338 { sid => $sid, fin => 1 }, 338 { sid => $sid, fin => 1 },
339 { sid => $sid2, fin => 1 }, 339 { sid => $sid2, fin => 1 },
340 { sid => $sid3, fin => 1 }, 340 { sid => $sid3, fin => 1 },
341 ]); 341 ]);
342 342
346 346
347 # PRIORITY - reprioritization with circular dependency - after [3] removed 347 # PRIORITY - reprioritization with circular dependency - after [3] removed
348 # initial dependency tree: 348 # initial dependency tree:
349 # 1 <- [3] <- 5 349 # 1 <- [3] <- 5
350 350
351 $sess = new_session(); 351 $s = Test::Nginx::HTTP2->new();
352 352
353 h2_window($sess, 2**18); 353 $s->h2_window(2**18);
354 354
355 h2_priority($sess, 16, 1, 0); 355 $s->h2_priority(16, 1, 0);
356 h2_priority($sess, 16, 3, 1); 356 $s->h2_priority(16, 3, 1);
357 h2_priority($sess, 16, 5, 3); 357 $s->h2_priority(16, 5, 3);
358 358
359 $sid = new_stream($sess, { path => '/t1.html' }); 359 $sid = $s->new_stream({ path => '/t1.html' });
360 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); 360 $s->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
361 361
362 $sid2 = new_stream($sess, { path => '/t1.html' }); 362 $sid2 = $s->new_stream({ path => '/t1.html' });
363 h2_read($sess, all => [{ sid => $sid2, length => 2**16 - 1 }]); 363 $s->read(all => [{ sid => $sid2, length => 2**16 - 1 }]);
364 364
365 $sid3 = new_stream($sess, { path => '/t1.html' }); 365 $sid3 = $s->new_stream({ path => '/t1.html' });
366 h2_read($sess, all => [{ sid => $sid3, length => 2**16 - 1 }]); 366 $s->read(all => [{ sid => $sid3, length => 2**16 - 1 }]);
367 367
368 h2_window($sess, 2**16, $sid2); 368 $s->h2_window(2**16, $sid2);
369 369
370 $frames = h2_read($sess, all => [{ sid => $sid2, fin => 1 }]); 370 $frames = $s->read(all => [{ sid => $sid2, fin => 1 }]);
371 $sids = join ' ', map { $_->{sid} } grep { $_->{type} eq "DATA" } @$frames; 371 $sids = join ' ', map { $_->{sid} } grep { $_->{type} eq "DATA" } @$frames;
372 is($sids, $sid2, 'removed dependency'); 372 is($sids, $sid2, 'removed dependency');
373 373
374 for (1 .. 40) { 374 for (1 .. 40) {
375 h2_read($sess, all => [{ sid => new_stream($sess), fin => 1 }]); 375 $s->read(all => [{ sid => $s->new_stream(), fin => 1 }]);
376 } 376 }
377 377
378 # make circular dependency 378 # make circular dependency
379 # 1 <- 5 -- current dependency tree before reprioritization 379 # 1 <- 5 -- current dependency tree before reprioritization
380 # 5 <- 1 380 # 5 <- 1
381 # 1 <- 5 381 # 1 <- 5
382 382
383 h2_priority($sess, 16, 1, 5); 383 $s->h2_priority(16, 1, 5);
384 h2_priority($sess, 16, 5, 1); 384 $s->h2_priority(16, 5, 1);
385 385
386 h2_window($sess, 2**16, $sid); 386 $s->h2_window(2**16, $sid);
387 h2_window($sess, 2**16, $sid3); 387 $s->h2_window(2**16, $sid3);
388 388
389 $frames = h2_read($sess, all => [ 389 $frames = $s->read(all => [
390 { sid => $sid, fin => 1 }, 390 { sid => $sid, fin => 1 },
391 { sid => $sid3, fin => 1 }, 391 { sid => $sid3, fin => 1 },
392 ]); 392 ]);
393 393
394 ($frame) = grep { $_->{type} eq "DATA" && $_->{sid} == $sid } @$frames; 394 ($frame) = grep { $_->{type} eq "DATA" && $_->{sid} == $sid } @$frames;
398 is($frame->{length}, 81, 'removed dependency - last stream'); 398 is($frame->{length}, 81, 'removed dependency - last stream');
399 399
400 # PRIORITY - reprioritization with circular dependency - exclusive [5] 400 # PRIORITY - reprioritization with circular dependency - exclusive [5]
401 # 1 <- [5] <- 3 401 # 1 <- [5] <- 3
402 402
403 $sess = new_session(); 403 $s = Test::Nginx::HTTP2->new();
404 404
405 h2_window($sess, 2**18); 405 $s->h2_window(2**18);
406 406
407 h2_priority($sess, 16, 1, 0); 407 $s->h2_priority(16, 1, 0);
408 h2_priority($sess, 16, 3, 1); 408 $s->h2_priority(16, 3, 1);
409 h2_priority($sess, 16, 5, 1, excl => 1); 409 $s->h2_priority(16, 5, 1, excl => 1);
410 410
411 $sid = new_stream($sess, { path => '/t1.html' }); 411 $sid = $s->new_stream({ path => '/t1.html' });
412 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); 412 $s->read(all => [{ sid => $sid, length => 2**16 - 1 }]);
413 413
414 $sid2 = new_stream($sess, { path => '/t1.html' }); 414 $sid2 = $s->new_stream({ path => '/t1.html' });
415 h2_read($sess, all => [{ sid => $sid2, length => 2**16 - 1 }]); 415 $s->read(all => [{ sid => $sid2, length => 2**16 - 1 }]);
416 416
417 $sid3 = new_stream($sess, { path => '/t1.html' }); 417 $sid3 = $s->new_stream({ path => '/t1.html' });
418 h2_read($sess, all => [{ sid => $sid3, length => 2**16 - 1 }]); 418 $s->read(all => [{ sid => $sid3, length => 2**16 - 1 }]);
419 419
420 h2_window($sess, 2**16, $sid); 420 $s->h2_window(2**16, $sid);
421 421
422 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); 422 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
423 $sids = join ' ', map { $_->{sid} } grep { $_->{type} eq "DATA" } @$frames; 423 $sids = join ' ', map { $_->{sid} } grep { $_->{type} eq "DATA" } @$frames;
424 is($sids, $sid, 'exclusive dependency - parent removed'); 424 is($sids, $sid, 'exclusive dependency - parent removed');
425 425
426 # make circular dependency 426 # make circular dependency
427 # 5 <- 3 -- current dependency tree before reprioritization 427 # 5 <- 3 -- current dependency tree before reprioritization
428 # 3 <- 5 428 # 3 <- 5
429 429
430 h2_priority($sess, 16, 5, 3); 430 $s->h2_priority(16, 5, 3);
431 431
432 h2_window($sess, 2**16, $sid2); 432 $s->h2_window(2**16, $sid2);
433 h2_window($sess, 2**16, $sid3); 433 $s->h2_window(2**16, $sid3);
434 434
435 $frames = h2_read($sess, all => [ 435 $frames = $s->read(all => [
436 { sid => $sid2, fin => 1 }, 436 { sid => $sid2, fin => 1 },
437 { sid => $sid3, fin => 1 }, 437 { sid => $sid3, fin => 1 },
438 ]); 438 ]);
439 439
440 ($frame) = grep { $_->{type} eq "DATA" && $_->{sid} == $sid2 } @$frames; 440 ($frame) = grep { $_->{type} eq "DATA" && $_->{sid} == $sid2 } @$frames;