view h3_reusable.t @ 1888:cc13f7b098db

Tests: avoid premature stream reset in h3_limit_req.t. STREAM and RESET_STREAM frames could be batched, which prevents the stream from being processed and changes the status code. The fix is to wait for the stream acknowledgment. Here we just look at the largest acknowledged, this should be enough for simple cases.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 04 Apr 2023 00:33:54 +0400
parents 33432a6877f7
children 8b74936ff2ac
line wrap: on
line source

#!/usr/bin/perl

# (C) Sergey Kandaurov
# (C) Nginx, Inc.

# Tests for HTTP/3, reusable connections.

###############################################################################

use warnings;
use strict;

use Test::More;

BEGIN { use FindBin; chdir($FindBin::Bin); }

use lib 'lib';
use Test::Nginx;
use Test::Nginx::HTTP3;

###############################################################################

select STDERR; $| = 1;
select STDOUT; $| = 1;

eval { require Crypt::Misc; die if $Crypt::Misc::VERSION < 0.067; };
plan(skip_all => 'CryptX version >= 0.067 required') if $@;

my $t = Test::Nginx->new()->has(qw/http http_v3/)
	->has_daemon('openssl')->plan(1)
	->write_file_expand('nginx.conf', <<'EOF');

%%TEST_GLOBALS%%

daemon off;

events {
    worker_connections 12;
}

http {
    %%TEST_GLOBALS_HTTP%%

    ssl_certificate_key localhost.key;
    ssl_certificate localhost.crt;

    server {
        listen       127.0.0.1:%%PORT_8980_UDP%% quic;
        server_name  localhost;

        location / { }
    }
}

EOF

$t->write_file('openssl.conf', <<EOF);
[ req ]
default_bits = 2048
encrypt_key = no
distinguished_name = req_distinguished_name
[ req_distinguished_name ]
EOF

my $d = $t->testdir();

foreach my $name ('localhost') {
	system('openssl req -x509 -new '
		. "-config $d/openssl.conf -subj /CN=$name/ "
		. "-out $d/$name.crt -keyout $d/$name.key "
		. ">>$d/openssl.out 2>&1") == 0
		or die "Can't create certificate for $name: $!\n";
}

$t->run();

###############################################################################

my $s1 = Test::Nginx::HTTP3->new();
$s1->insert_literal(':path', '/foo');
$s1->read(all => [ { type => 'DECODER_ICI' } ]);

# expect to steal reusable worker connections

my $s2 = Test::Nginx::HTTP3->new();
$s2->start_chain();
my @sids = map { $s2->new_stream() } 1 .. 5;
$s2->send_chain();
my $frames = $s2->read(all => [ map { { sid => $_, fin => 1 } } @sids ]);

my $streams = grep { $_->{type} eq "HEADERS" } @$frames;
is($streams, 5, 'streams');

###############################################################################