Debian Codegraph @

t/08_priority.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4 use lib 't/lib';
5 use PH2Test;
6 use Protocol::HTTP2::Constants qw(const_name :frame_types :endpoints :states
7 :flags);
8 use Protocol::HTTP2::Connection;
9
10 subtest 'priority frame' => sub {
11
12 my $con = Protocol::HTTP2::Connection->new(SERVER);
13
14 my $frame = $con->frame_encode( PRIORITY, 0, 1, [ 0, 32 ] );
15 ok binary_eq( $frame, hstr("0000 0502 0000 0000 0100 0000 001f") ),
16 "PRIORITY";
17
18 # Simulate client request
19 $con->preface(1);
20 $con->new_peer_stream(1);
21
22 my $res = $con->frame_decode( \$frame, 0 );
23 is $res, 14, "decoded correctly";
24
25 $frame = $con->frame_encode( HEADERS,
26 END_HEADERS,
27 1,
28 {
29 hblock => \hstr("41 8aa0 e41d 139d 09b8 f000 0f82 8486"),
30 stream_dep => 0,
31 weight => 32
32 }
33 );
34
35 ok binary_eq(
36 $frame,
37 hstr(
38 "0000 1401 2400 0000 0100 0000 001f 418a"
39 . "a0e4 1d13 9d09 b8f0 000f 8284 86"
40 )
41 ),
42 "Headers with priority";
43
44 $res = $con->frame_decode( \$frame, 0 );
45 is $res, 29, "decoded correctly";
46 };
47
48 subtest 'stream reprioritization' => sub {
49
50 my $con = Protocol::HTTP2::Connection->new(SERVER);
51
52 # Simulate client request
53 $con->preface(1);
54 $con->new_peer_stream(1);
55 $con->new_peer_stream(3);
56 $con->new_peer_stream(5);
57
58 # 0
59 # /|\
60 # 1 3 5
61
62 ok $con->stream_reprio( 1, 1, 0 ), "stream_reprio exclusive 1 done";
63
64 # 1
65 # / \
66 # 3 5
67
68 is $con->stream(1)->{stream_dep}, 0, "1 on top";
69 is $con->stream(3)->{stream_dep}, 1, "3 under 1";
70 is $con->stream(5)->{stream_dep}, 1, "5 under 1";
71
72 $con->new_peer_stream(7);
73 ok $con->stream_reprio( 7, 0, 1 ), "stream_reprio 7";
74 $con->new_peer_stream(9);
75 ok $con->stream_reprio( 9, 0, 7 ), "stream_reprio 9";
76 $con->new_peer_stream(11);
77 ok $con->stream_reprio( 11, 0, 9 ), "stream_reprio 11";
78
79 ok $con->stream_reprio( 1, 0, 9 ), "stream_reprio 1 under 9";
80
81 #
82 # 1 9
83 # / | \ / \
84 # 3 5 7 11 1
85 # \ => / | \
86 # 9 3 5 7
87 # \
88 # 11
89
90 is $con->stream(9)->{stream_dep}, 0, "9 on top";
91 is $con->stream(11)->{stream_dep}, 9, "11 under 9";
92 is $con->stream(1)->{stream_dep}, 9, "1 under 9";
93 is $con->stream(3)->{stream_dep}, 1, "3 under 1";
94 is $con->stream(5)->{stream_dep}, 1, "3 under 1";
95 is $con->stream(7)->{stream_dep}, 1, "7 under 1";
96
97 #diag explain $con->{streams};
98 };
99
100 done_testing;