File: 07_ping.t

package info (click to toggle)
libprotocol-http2-perl 1.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 448 kB
  • sloc: perl: 3,370; makefile: 7
file content (65 lines) | stat: -rw-r--r-- 1,868 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use strict;
use warnings;
use Test::More;
use lib 't/lib';
use PH2Test;
use Protocol::HTTP2::Constants qw(const_name :frame_types :endpoints :states
  :flags);
use Protocol::HTTP2::Connection;
use Protocol::HTTP2::Client;
use Protocol::HTTP2::Server;

subtest 'ping' => sub {

    my $client = Protocol::HTTP2::Client->new;
    $client->request(
        ':authority' => 'localhost',
        ':method'    => 'GET',
        ':path'      => '/',
        ':scheme'    => 'https',
    );

    my $server = Protocol::HTTP2::Server->new;

    while ( my $frame = $client->next_frame ) {
        $server->feed($frame);
        while ( $frame = $server->next_frame ) {
            $client->feed($frame);
        }
    }

    $client->ping("HELLOSRV");
    my $ping = $client->next_frame;
    ok binary_eq( $ping, hstr("0000 0806 0000 0000 0048 454c 4c4f 5352 56") ),
      "ping";
    $server->feed($ping);
    ok binary_eq( $ping = $server->next_frame,
        hstr("0000 0806 0100 0000 0048 454c 4c4f 5352 56") ),
      "ping ack";
    is $server->next_frame, undef;
    $client->feed($ping);
    is $client->next_frame, undef;
};

subtest 'dont mess with continuation' => sub {
    my $con = Protocol::HTTP2::Connection->new(CLIENT);
    $con->preface(1);

    $con->new_stream(1);
    my @hdrs = ( HEADERS, 0, 1, { hblock => \"\x82" } );
    my @cont = ( CONTINUATION, END_HEADERS, 1, \"\x85" );
    my @data = ( DATA, 0, 1, \"DATA" );

    $con->enqueue( @hdrs, @cont, @data );

    ok binary_eq( $con->dequeue, $con->frame_encode(@hdrs) ), "1-HEADER";

    my @ping = ( PING, 0, 0, \"HELLOSRV" );
    $con->enqueue_first(@ping);

    ok binary_eq( $con->dequeue, $con->frame_encode(@cont) ), "2-CONTINUATION";
    ok binary_eq( $con->dequeue, $con->frame_encode(@ping) ), "3-PING";
    ok binary_eq( $con->dequeue, $con->frame_encode(@data) ), "4-DATA";
};

done_testing