Mercurial > hg > nginx-tests
annotate h2_max_requests.t @ 1539:57a92c20f974
Tests: discarded request body in error_page redirect.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 27 Dec 2019 11:59:19 +0300 |
parents | 766bcbb632ee |
children | 14eeaa39599d |
rev | line source |
---|---|
1077
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for HTTP/2 protocol, http2_max_requests directive. |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::HTTP2; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http http_v2/) |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 ->write_file_expand('nginx.conf', <<'EOF'); |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 server { |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 listen 127.0.0.1:8080 http2; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server_name localhost; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 http2_max_requests 2; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 location / { } |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 } |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 } |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 EOF |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 $t->write_file('index.html', ''); |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1077
diff
changeset
|
52 $t->run()->plan(5); |
1077
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 ############################################################################### |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 my $s = Test::Nginx::HTTP2->new(); |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 my $frames = $s->read(all => [{ sid => $s->new_stream(), fin => 1 }]); |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 is($frame->{headers}->{':status'}, 200, 'max requests'); |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 $frames = $s->read(all => [{ type => 'GOAWAY' }], wait => 0.5) |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 unless grep { $_->{type} eq "GOAWAY" } @$frames; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 is($frame, undef, 'max requests - GOAWAY'); |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 # max requests limited |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 my $sid = $s->new_stream(); |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 $frames = $s->read(all => [{ sid => $sid, fin => 1 }, { type => 'GOAWAY' }]); |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 is($frame->{headers}->{':status'}, 200, 'max requests limited'); |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 ok($frame, 'max requests limited - GOAWAY'); |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 is($frame->{last_sid}, $sid, 'max requests limited - GOAWAY last stream'); |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 ############################################################################### |