view h3_reusable.t @ 1943:1786f49cca17

Tests: fixed spurious http_resolver_ipv4.t failures. Previously, to get resolved addresses, the test relied on cached random rotation in resolver, such that a chosen address is eventually changed, which may not happen after several client requests. For this reason, the test is rewritten to get all addresses by switching to the next upstream.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 22 Jan 2024 14:11:12 +0400
parents 8b74936ff2ac
children
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;

my $t = Test::Nginx->new()->has(qw/http http_v3 cryptx/)
	->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');

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