comparison h2_proxy_cache.t @ 985:de513b115e68

Tests: renamed some HTTP/2 tests to follow naming convention.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 20 Jul 2016 11:07:20 +0300
parents h2_cache.t@882267679006
children 99f93be57416
comparison
equal deleted inserted replaced
984:892737e9fd31 985:de513b115e68
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for HTTP/2 protocol with cache.
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
26 my $t = Test::Nginx->new()->has(qw/http http_v2 proxy cache/)->plan(11)
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 proxy_cache_path %%TESTDIR%%/cache keys_zone=NAME: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 /cache {
47 proxy_pass http://127.0.0.1:8081/;
48 proxy_cache NAME;
49 proxy_cache_valid 1m;
50 }
51 location /proxy_buffering_off {
52 proxy_pass http://127.0.0.1:8081/;
53 proxy_cache NAME;
54 proxy_cache_valid 1m;
55 proxy_buffering off;
56 }
57 }
58 }
59
60 EOF
61
62 $t->write_file('t.html', 'SEE-THIS');
63 $t->run();
64
65 ###############################################################################
66
67 # simple proxy cache test
68
69 my $s = Test::Nginx::HTTP2->new();
70 my $sid = $s->new_stream({ path => '/cache/t.html' });
71 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
72
73 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
74 is($frame->{headers}->{':status'}, '200', 'proxy cache');
75
76 my $etag = $frame->{headers}->{'etag'};
77
78 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
79 is($frame->{length}, length 'SEE-THIS', 'proxy cache - DATA');
80 is($frame->{data}, 'SEE-THIS', 'proxy cache - DATA payload');
81
82 $t->write_file('t.html', 'NOOP');
83
84 $sid = $s->new_stream({ headers => [
85 { name => ':method', value => 'GET', mode => 0 },
86 { name => ':scheme', value => 'http', mode => 0 },
87 { name => ':path', value => '/cache/t.html' },
88 { name => ':authority', value => 'localhost', mode => 1 },
89 { name => 'if-none-match', value => $etag }]});
90 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
91
92 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
93 is($frame->{headers}->{':status'}, 304, 'proxy cache conditional');
94
95 $t->write_file('t.html', 'SEE-THIS');
96
97 # request body with cached response
98
99 $sid = $s->new_stream({ path => '/cache/t.html', body_more => 1 });
100 $s->h2_body('TEST');
101 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
102
103 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
104 is($frame->{headers}->{':status'}, 200, 'proxy cache - request body');
105
106 $s->h2_ping('SEE-THIS');
107 $frames = $s->read(all => [{ type => 'PING' }]);
108
109 ($frame) = grep { $_->{type} eq "PING" && $_->{flags} & 0x1 } @$frames;
110 ok($frame, 'proxy cache - request body - next');
111
112 # HEADERS could be received with fin, followed by DATA
113
114 $s = Test::Nginx::HTTP2->new();
115 $sid = $s->new_stream({ path => '/cache/t.html?1', method => 'HEAD' });
116
117 $frames = $s->read(all => [{ sid => $sid, fin => 1 }], wait => 0.2);
118 push @$frames, $_ for @{$s->read(all => [{ sid => $sid }], wait => 0.2)};
119 ok(!grep ({ $_->{type} eq "DATA" } @$frames), 'proxy cache HEAD - no body');
120
121 # proxy cache - expect no stray empty DATA frame
122
123 TODO: {
124 local $TODO = 'not yet';
125
126 $s = Test::Nginx::HTTP2->new();
127 $sid = $s->new_stream({ path => '/cache/t.html?2' });
128
129 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
130 my @data = grep ({ $_->{type} eq "DATA" } @$frames);
131 is(@data, 1, 'proxy cache write - data frames');
132 is(join(' ', map { $_->{data} } @data), 'SEE-THIS', 'proxy cache write - data');
133 is(join(' ', map { $_->{flags} } @data), '1', 'proxy cache write - flags');
134
135 }
136
137 # HEAD on empty cache with proxy_buffering off
138
139 $s = Test::Nginx::HTTP2->new();
140 $sid = $s->new_stream(
141 { path => '/proxy_buffering_off/t.html?1', method => 'HEAD' });
142
143 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
144 push @$frames, $_ for @{$s->read(all => [{ sid => $sid }], wait => 0.2)};
145 ok(!grep ({ $_->{type} eq "DATA" } @$frames),
146 'proxy cache HEAD buffering off - no body');
147
148 ###############################################################################