Mercurial > hg > nginx-tests
annotate h2_trailers.t @ 1427:eb1d883305ea
Tests: avoid edge cases in upstream random two test.
Unavailable servers contribute to the number of attempts, if selected,
before the balancer would fall back to the default round-robin method.
This means that it's quite possible to get server with more connections.
To facilitate with selecting two alive servers, down server was removed
from the upstream configuration at the cost of slightly worse coverage.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 10 Jan 2019 17:42:34 +0300 |
parents | 97c8280de681 |
children | 5b1fa6e32549 |
rev | line source |
---|---|
1193 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for HTTP/2 trailers. | |
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; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1194
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http http_v2/)->plan(22) |
1193 | 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 server { | |
40 listen 127.0.0.1:8080 http2; | |
41 server_name localhost; | |
42 | |
43 location / { | |
44 add_trailer X-Var $host; | |
45 } | |
46 | |
47 http2_max_field_size 256k; | |
48 | |
49 location /continuation { | |
50 # many trailers to send in parts | |
51 add_trailer X-LongHeader $arg_h; | |
52 add_trailer X-LongHeader $arg_h; | |
53 add_trailer X-LongHeader $arg_h; | |
54 add_trailer X-LongHeader $arg_h; | |
55 add_trailer X-LongHeader $arg_h; | |
56 } | |
57 } | |
58 } | |
59 | |
60 EOF | |
61 | |
62 $t->write_file('index.html', 'SEE-THIS'); | |
63 $t->write_file('empty', ''); | |
64 $t->write_file('continuation', 'SEE-THIS'); | |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1194
diff
changeset
|
65 $t->run(); |
1193 | 66 |
67 ############################################################################### | |
68 | |
69 my ($s, $sid, $frames, $frame); | |
70 | |
71 $s = Test::Nginx::HTTP2->new(); | |
72 $sid = $s->new_stream({ path => '/' }); | |
73 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | |
74 @$frames = grep { $_->{type} =~ "HEADERS|DATA" } @$frames; | |
75 | |
76 is(@$frames, 3, 'frames'); | |
77 | |
78 $frame = shift @$frames; | |
79 is($frame->{headers}->{':status'}, 200, 'header'); | |
80 is($frame->{headers}->{'x-var'}, undef, 'header not trailer'); | |
81 is($frame->{flags}, 4, 'header flags'); | |
82 | |
83 $frame = shift @$frames; | |
84 is($frame->{data}, 'SEE-THIS', 'data'); | |
85 is($frame->{flags}, 0, 'data flags'); | |
86 | |
87 $frame = shift @$frames; | |
88 is($frame->{headers}->{'x-var'}, 'localhost', 'trailer'); | |
89 is($frame->{flags}, 5, 'trailer flags'); | |
90 | |
91 # with zero content-length | |
92 | |
93 $s = Test::Nginx::HTTP2->new(); | |
94 $sid = $s->new_stream({ path => '/empty' }); | |
95 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | |
96 @$frames = grep { $_->{type} =~ "HEADERS|DATA" } @$frames; | |
97 | |
98 is(@$frames, 2, 'no data - frames'); | |
99 | |
100 $frame = shift @$frames; | |
101 is($frame->{headers}->{':status'}, 200, 'no data - header'); | |
102 is($frame->{flags}, 4, 'no data - header flags'); | |
103 | |
104 $frame = shift @$frames; | |
105 is($frame->{headers}->{'x-var'}, 'localhost', 'no data - trailer'); | |
106 is($frame->{flags}, 5, 'no data - trailer flags'); | |
107 | |
108 # CONTINUATION in response trailers | |
109 | |
110 $s = Test::Nginx::HTTP2->new(); | |
111 $sid = $s->new_stream({ path => '/continuation?h=' . 'x' x 2**12 }); | |
1194
39cfdf581253
Tests: fixed CONTINUATION test in h2_trailers.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1193
diff
changeset
|
112 $frames = $s->read(all => [{ sid => $sid, type => 'CONTINUATION' }]); |
1193 | 113 @$frames = grep { $_->{type} =~ "HEADERS|CONTINUATION|DATA" } @$frames; |
114 | |
115 is(@$frames, 4, 'continuation - frames'); | |
116 | |
117 $frame = shift @$frames; | |
118 is($frame->{headers}->{':status'}, 200, 'continuation - header'); | |
119 is($frame->{flags}, 4, 'continuation - header flags'); | |
120 | |
121 $frame = shift @$frames; | |
122 is($frame->{data}, 'SEE-THIS', 'continuation - data'); | |
123 is($frame->{flags}, 0, 'continuation - data flags'); | |
124 | |
125 $frame = shift @$frames; | |
126 is($frame->{type}, 'HEADERS', 'continuation - trailer'); | |
127 is($frame->{flags}, 1, 'continuation - trailer flags'); | |
128 | |
129 $frame = shift @$frames; | |
130 is($frame->{type}, 'CONTINUATION', 'continuation - trailer continuation'); | |
131 is($frame->{flags}, 4, 'continuation - trailer continuation flags'); | |
132 | |
133 ############################################################################### |