Mercurial > hg > nginx-tests
comparison h2_limit_conn.t @ 876:a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Wed, 23 Mar 2016 17:23:08 +0300 |
parents | |
children | 724fcee9a355 |
comparison
equal
deleted
inserted
replaced
875:c380b4b7e2e4 | 876:a6abbfed42c0 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for HTTP/2 protocol with limit_conn. | |
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::HTTP2 qw/ :DEFAULT :frame /; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
26 my $t = Test::Nginx->new()->has(qw/http http_v2 limit_conn/)->plan(4) | |
27 ->write_file_expand('nginx.conf', <<'EOF'); | |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 limit_conn_zone $binary_remote_addr zone=conn:1m; | |
40 | |
41 server { | |
42 listen 127.0.0.1:8080 http2; | |
43 listen 127.0.0.1:8081; | |
44 server_name localhost; | |
45 | |
46 location /t.html { | |
47 limit_conn conn 1; | |
48 } | |
49 } | |
50 } | |
51 | |
52 EOF | |
53 | |
54 $t->write_file('t.html', 'SEE-THIS'); | |
55 $t->run(); | |
56 | |
57 ############################################################################### | |
58 | |
59 my $sess = new_session(); | |
60 h2_settings($sess, 0, 0x4 => 1); | |
61 | |
62 my $sid = new_stream($sess, { path => '/t.html' }); | |
63 my $frames = h2_read($sess, all => [{ sid => $sid, length => 1 }]); | |
64 | |
65 my ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid } @$frames; | |
66 is($frame->{headers}->{':status'}, 200, 'limit_conn first stream'); | |
67 | |
68 my $sid2 = new_stream($sess, { path => '/t.html' }); | |
69 $frames = h2_read($sess, all => [{ sid => $sid2, fin => 0 }]); | |
70 | |
71 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid2 } @$frames; | |
72 is($frame->{headers}->{':status'}, 503, 'limit_conn rejected'); | |
73 | |
74 h2_settings($sess, 0, 0x4 => 2**16); | |
75 | |
76 h2_read($sess, all => [ | |
77 { sid => $sid, fin => 1 }, | |
78 { sid => $sid2, fin => 1 } | |
79 ]); | |
80 | |
81 # limit_conn + client's RST_STREAM | |
82 | |
83 $sess = new_session(); | |
84 h2_settings($sess, 0, 0x4 => 1); | |
85 | |
86 $sid = new_stream($sess, { path => '/t.html' }); | |
87 $frames = h2_read($sess, all => [{ sid => $sid, length => 1 }]); | |
88 h2_rst($sess, $sid, 5); | |
89 | |
90 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid } @$frames; | |
91 is($frame->{headers}->{':status'}, 200, 'RST_STREAM 1'); | |
92 | |
93 $sid2 = new_stream($sess, { path => '/t.html' }); | |
94 $frames = h2_read($sess, all => [{ sid => $sid2, fin => 0 }]); | |
95 | |
96 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid2 } @$frames; | |
97 is($frame->{headers}->{':status'}, 200, 'RST_STREAM 2'); | |
98 | |
99 ############################################################################### |