Mercurial > hg > nginx-tests
changeset 1881:33432a6877f7
Tests: reusable HTTP/3 worker connections.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 12 Jan 2023 21:56:27 +0400 |
parents | 03cebb996b5b |
children | 3619dcc8ba6d |
files | h3_reusable.t |
diffstat | 1 files changed, 94 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/h3_reusable.t Thu Jan 12 21:56:27 2023 +0400 @@ -0,0 +1,94 @@ +#!/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'); + +###############################################################################