Mercurial > hg > nginx-tests
annotate h2_limit_conn.t @ 1600:b61e820caa83
Tests: using Sys::Hostname to get hostname in a portable way.
The hostname utility is not defined by POSIX and not available
by default on some modern Linux distro's (Arch, Fedora).
Reported by Geert Hendrickx.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 12 Oct 2020 18:13:07 +0100 |
parents | 882267679006 |
children | 236d038dc04a |
rev | line source |
---|---|
876
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Tests for HTTP/2 protocol with limit_conn. |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
948
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
19 use Test::Nginx::HTTP2; |
876
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
25 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http http_v2 limit_conn/)->plan(4) |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 ->write_file_expand('nginx.conf', <<'EOF'); |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 events { |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 } |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 http { |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 limit_conn_zone $binary_remote_addr zone=conn:1m; |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
40 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
41 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
42 listen 127.0.0.1:8080 http2; |
876
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
43 server_name localhost; |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 location /t.html { |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 limit_conn conn 1; |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 } |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 } |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 } |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 EOF |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 $t->write_file('t.html', 'SEE-THIS'); |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 $t->run(); |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 ############################################################################### |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 |
948
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
58 my $s = Test::Nginx::HTTP2->new(); |
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
59 $s->h2_settings(0, 0x4 => 1); |
876
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 |
948
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
61 my $sid = $s->new_stream({ path => '/t.html' }); |
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
62 my $frames = $s->read(all => [{ sid => $sid, length => 1 }]); |
876
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 my ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid } @$frames; |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 is($frame->{headers}->{':status'}, 200, 'limit_conn first stream'); |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 |
948
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
67 my $sid2 = $s->new_stream({ path => '/t.html' }); |
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
68 $frames = $s->read(all => [{ sid => $sid2, length => 1 }]); |
876
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid2 } @$frames; |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 is($frame->{headers}->{':status'}, 503, 'limit_conn rejected'); |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 |
948
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
73 $s->h2_settings(0, 0x4 => 2**16); |
876
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 |
948
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
75 $s->read(all => [ |
876
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 { sid => $sid, fin => 1 }, |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 { sid => $sid2, fin => 1 } |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 ]); |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
80 # limit_conn + client's RST_STREAM |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 |
948
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
82 $s = Test::Nginx::HTTP2->new(); |
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
83 $s->h2_settings(0, 0x4 => 1); |
876
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
84 |
948
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
85 $sid = $s->new_stream({ path => '/t.html' }); |
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
86 $frames = $s->read(all => [{ sid => $sid, length => 1 }]); |
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
87 $s->h2_rst($sid, 5); |
876
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid } @$frames; |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
90 is($frame->{headers}->{':status'}, 200, 'RST_STREAM 1'); |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
91 |
948
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
92 $sid2 = $s->new_stream({ path => '/t.html' }); |
4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Sergey Kandaurov <pluknet@nginx.com>
parents:
945
diff
changeset
|
93 $frames = $s->read(all => [{ sid => $sid2, length => 1 }]); |
876
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
94 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
95 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid2 } @$frames; |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
96 is($frame->{headers}->{':status'}, 200, 'RST_STREAM 2'); |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
97 |
a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
98 ############################################################################### |