Mercurial > hg > nginx-tests
annotate h2_max_requests.t @ 1240:f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
When the testing script is run in verbose mode by prove that redirects stdout,
a garbled verbose mode line from backend can be produced that incorporates TAP
output of an individual test result, which eventually breaks the testing plan.
Notably, this happens when testing sending multiple frames if backend started
to respond before all frames were received. This is possible due to the line
boundary used as an indicator of last bytes to receive before starting to send.
The fix is to amend the only last frame of many specially, for that purpose.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 15 Nov 2017 20:16:09 +0300 |
parents | 13247bbc1f7d |
children | 766bcbb632ee |
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', ''); |
13247bbc1f7d
Tests: HTTP/2 tests for max requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 $t->try_run('no http2_max_requests')->plan(5); |
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 ############################################################################### |