|
| 1 | +#!/usr/bin/perl |
| 2 | + |
| 3 | +# (C) Sergey Kandaurov |
| 4 | +# (C) Nginx, Inc. |
| 5 | + |
| 6 | +# Tests for HTTP/3, sending ACK frames on congested network. |
| 7 | + |
| 8 | +############################################################################### |
| 9 | + |
| 10 | +use warnings; |
| 11 | +use strict; |
| 12 | + |
| 13 | +use Test::More; |
| 14 | + |
| 15 | +BEGIN { use FindBin; chdir($FindBin::Bin); } |
| 16 | + |
| 17 | +use lib 'lib'; |
| 18 | +use Test::Nginx; |
| 19 | +use Test::Nginx::HTTP3; |
| 20 | + |
| 21 | +############################################################################### |
| 22 | + |
| 23 | +select STDERR; $| = 1; |
| 24 | +select STDOUT; $| = 1; |
| 25 | + |
| 26 | +my $t = Test::Nginx->new()->has(qw/http http_v3 cryptx/) |
| 27 | + ->has_daemon('openssl')->plan(3) |
| 28 | + ->write_file_expand('nginx.conf', <<'EOF'); |
| 29 | +
|
| 30 | +%%TEST_GLOBALS%% |
| 31 | +
|
| 32 | +daemon off; |
| 33 | +
|
| 34 | +events { |
| 35 | +} |
| 36 | +
|
| 37 | +http { |
| 38 | + %%TEST_GLOBALS_HTTP%% |
| 39 | +
|
| 40 | + ssl_certificate_key localhost.key; |
| 41 | + ssl_certificate localhost.crt; |
| 42 | +
|
| 43 | + server { |
| 44 | + listen 127.0.0.1:%%PORT_8980_UDP%% quic; |
| 45 | + server_name localhost; |
| 46 | + } |
| 47 | +} |
| 48 | +
|
| 49 | +EOF |
| 50 | + |
| 51 | +$t->write_file('openssl.conf', <<EOF); |
| 52 | +[ req ] |
| 53 | +default_bits = 2048 |
| 54 | +encrypt_key = no |
| 55 | +distinguished_name = req_distinguished_name |
| 56 | +[ req_distinguished_name ] |
| 57 | +EOF |
| 58 | + |
| 59 | +my $d = $t->testdir(); |
| 60 | + |
| 61 | +foreach my $name ('localhost') { |
| 62 | + system('openssl req -x509 -new ' |
| 63 | + . "-config $d/openssl.conf -subj /CN=$name/ " |
| 64 | + . "-out $d/$name.crt -keyout $d/$name.key " |
| 65 | + . ">>$d/openssl.out 2>&1") == 0 |
| 66 | + or die "Can't create certificate for $name: $!\n"; |
| 67 | +} |
| 68 | + |
| 69 | +$t->run(); |
| 70 | + |
| 71 | +# rough estimate to fill initial congestion window |
| 72 | +$t->write_file('index.html', 'xSEE-THISx' x 1300); |
| 73 | + |
| 74 | +############################################################################### |
| 75 | + |
| 76 | +my ($s, $sid, $frames, $frame); |
| 77 | + |
| 78 | +$s = Test::Nginx::HTTP3->new(); |
| 79 | +$sid = $s->new_stream(); |
| 80 | + |
| 81 | +select undef, undef, undef, 0.2; |
| 82 | + |
| 83 | +# expect PING acknowledgment to ignore congestion control |
| 84 | +# while keeping the in-flight bytes counter high on server |
| 85 | + |
| 86 | +$s->{send_ack} = 0; |
| 87 | +$s->ping(); |
| 88 | +my $largest = $s->{pn}[0][3]; |
| 89 | + |
| 90 | +while (1) { |
| 91 | + my $rcvd = $s->read(all => [{ type => 'ACK' }], wait => 0.2); |
| 92 | + push @$frames, $_ for @$rcvd; |
| 93 | + |
| 94 | + ($frame) = grep { $_->{type} eq "ACK" } @$rcvd; |
| 95 | + last unless $frame; |
| 96 | + last if $frame->{'largest'} == $largest; |
| 97 | +}; |
| 98 | + |
| 99 | +TODO: { |
| 100 | +local $TODO = 'not yet' unless $t->has_version('1.29.0'); |
| 101 | + |
| 102 | +is($frame->{'largest'}, $largest, 'PING acked'); |
| 103 | + |
| 104 | +} |
| 105 | + |
| 106 | +# make sure the requested stream is fully received |
| 107 | + |
| 108 | +$s->{send_ack} = 1; |
| 109 | + |
| 110 | +push @$frames, $_ for @{$s->read(all => [{ sid => $sid, fin => 1 }])}; |
| 111 | + |
| 112 | +($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
| 113 | +is($frame->{headers}->{':status'}, 200, 'request'); |
| 114 | + |
| 115 | +($frame) = grep { $_->{type} eq "DATA" } @$frames; |
| 116 | +is($frame->{'length'}, 13000, 'body'); |
| 117 | + |
| 118 | +############################################################################### |
0 commit comments