Mercurial > hg > nginx-tests
comparison h3_keepalive.t @ 1878:b69bae343c53
Tests: HTTP/3 keepalive tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 12 Jan 2023 14:09:25 +0400 |
parents | |
children | 8b74936ff2ac |
comparison
equal
deleted
inserted
replaced
1877:dc0bda44044c | 1878:b69bae343c53 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for HTTP/3 protocol, keepalive directives. | |
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 eval { require Crypt::Misc; die if $Crypt::Misc::VERSION < 0.067; }; | |
27 plan(skip_all => 'CryptX version >= 0.067 required') if $@; | |
28 | |
29 my $t = Test::Nginx->new()->has(qw/http http_v3/) | |
30 ->has_daemon('openssl')->plan(15) | |
31 ->write_file_expand('nginx.conf', <<'EOF'); | |
32 | |
33 %%TEST_GLOBALS%% | |
34 | |
35 daemon off; | |
36 | |
37 events { | |
38 } | |
39 | |
40 http { | |
41 %%TEST_GLOBALS_HTTP%% | |
42 | |
43 ssl_certificate_key localhost.key; | |
44 ssl_certificate localhost.crt; | |
45 | |
46 server { | |
47 listen 127.0.0.1:%%PORT_8980_UDP%% quic; | |
48 server_name localhost; | |
49 | |
50 keepalive_requests 2; | |
51 | |
52 location / { } | |
53 } | |
54 | |
55 server { | |
56 listen 127.0.0.1:%%PORT_8981_UDP%% quic; | |
57 server_name localhost; | |
58 | |
59 keepalive_timeout 0; | |
60 | |
61 location / { } | |
62 } | |
63 | |
64 server { | |
65 listen 127.0.0.1:%%PORT_8982_UDP%% quic; | |
66 server_name localhost; | |
67 | |
68 keepalive_time 1s; | |
69 | |
70 add_header X-Conn $connection_requests:$connection_time; | |
71 | |
72 location / { } | |
73 } | |
74 } | |
75 | |
76 EOF | |
77 | |
78 $t->write_file('openssl.conf', <<EOF); | |
79 [ req ] | |
80 default_bits = 2048 | |
81 encrypt_key = no | |
82 distinguished_name = req_distinguished_name | |
83 [ req_distinguished_name ] | |
84 EOF | |
85 | |
86 my $d = $t->testdir(); | |
87 | |
88 foreach my $name ('localhost') { | |
89 system('openssl req -x509 -new ' | |
90 . "-config $d/openssl.conf -subj /CN=$name/ " | |
91 . "-out $d/$name.crt -keyout $d/$name.key " | |
92 . ">>$d/openssl.out 2>&1") == 0 | |
93 or die "Can't create certificate for $name: $!\n"; | |
94 } | |
95 | |
96 $t->write_file('index.html', 'SEE-THIS'); | |
97 | |
98 $t->run(); | |
99 | |
100 ############################################################################### | |
101 | |
102 my ($s, $sid, $frames, $frame); | |
103 | |
104 # max requests limited | |
105 | |
106 $s = Test::Nginx::HTTP3->new(); | |
107 $frames = $s->read(all => [{ sid => $s->new_stream(), fin => 1 }]); | |
108 | |
109 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
110 is($frame->{headers}->{':status'}, 200, 'keepalive requests 1'); | |
111 | |
112 $frames = $s->read(all => [ | |
113 { sid => $s->new_stream(), fin => 1 }, | |
114 { type => 'GOAWAY' } | |
115 ]); | |
116 | |
117 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
118 is($frame->{headers}->{':status'}, 200, 'keepalive requests 2'); | |
119 | |
120 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
121 is($frame->{sid}, 3, 'keepalive requests - GOAWAY stream type'); | |
122 is($frame->{last_sid}, 8, 'keepalive requests - GOAWAY last stream'); | |
123 | |
124 # keepalive_timeout 0 | |
125 # currently, keepalive timer is set before reading 1st request | |
126 # and there is no special handling for zero value timeout | |
127 | |
128 $s = Test::Nginx::HTTP3->new(8981); | |
129 | |
130 TODO: { | |
131 todo_skip 'keepalive_timeout 0', 2 unless $s; | |
132 | |
133 $sid = $s->new_stream(); | |
134 $frames = $s->read(all => [{ sid => $sid, fin => 1 }, { type => 'GOAWAY' }]); | |
135 | |
136 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
137 is($frame->{headers}->{':status'}, 200, 'keepalive_timeout 0'); | |
138 | |
139 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
140 ok($frame, 'keepalive_timeout 0 - GOAWAY'); | |
141 | |
142 } | |
143 | |
144 # keepalive_time | |
145 | |
146 $s = Test::Nginx::HTTP3->new(8982); | |
147 $sid = $s->new_stream(); | |
148 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | |
149 | |
150 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
151 is($frame->{headers}->{':status'}, 200, 'keepalive time request'); | |
152 like($frame->{headers}->{'x-conn'}, qr/^1:0/, 'keepalive time variables'); | |
153 | |
154 $frames = $s->read(all => [{ type => 'GOAWAY' }], wait => 0.5); | |
155 | |
156 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
157 is($frame, undef, 'keepalive time - no GOAWAY yet'); | |
158 | |
159 select undef, undef, undef, 1.1; | |
160 | |
161 $sid = $s->new_stream(); | |
162 $frames = $s->read(all => [{ sid => $sid, fin => 1 }, { type => 'GOAWAY' }]); | |
163 | |
164 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
165 is($frame->{headers}->{':status'}, 200, 'keepalive time request 2'); | |
166 like($frame->{headers}->{'x-conn'}, qr/^2:[^0]/, 'keepalive time variables 2'); | |
167 | |
168 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
169 is($frame->{sid}, 3, 'keepalive time limit - GOAWAY stream type'); | |
170 is($frame->{last_sid}, 8, 'keepalive time limit - GOAWAY last stream'); | |
171 | |
172 # graceful shutdown in idle state | |
173 | |
174 $s = Test::Nginx::HTTP3->new(); | |
175 $sid = $s->new_stream(); | |
176 | |
177 $t->reload(); | |
178 | |
179 $frames = $s->read(all => [{ type => 'GOAWAY' }]); | |
180 | |
181 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
182 is($frame->{sid}, 3, 'graceful shutdown - GOAWAY stream type'); | |
183 is($frame->{last_sid}, 4, 'graceful shutdown - GOAWAY last stream'); | |
184 | |
185 ############################################################################### |