Skip to content

Commit 551a9e4

Browse files
committed
Tests: add proxy_http2_cache.t for HTTP/2 proxy with cache support.
This is a basic test for cache functionality. More comprehensive tests will be added later.
1 parent 1c8825a commit 551a9e4

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

proxy_http2_cache.t

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ select STDERR; $| = 1;
2424
select STDOUT; $| = 1;
2525

2626
my $t = Test::Nginx->new()->has(qw/http rewrite http_v2 proxy cache/)
27-
->has(qw/upstream_keepalive/)->plan(2);
27+
->has(qw/upstream_keepalive/)->plan(3);
2828

2929
$t->write_file_expand('nginx.conf', <<'EOF');
3030
@@ -84,17 +84,11 @@ $frames = $f->{http_end}();
8484
($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
8585
like($frame->{headers}{'x-cache-status'}, qr/MISS/, 'cache test - MISS on first request');
8686

87-
# Test cached response - second request should be HIT
87+
# Second request - should be HIT from cache
8888

89-
undef $f;
90-
$f = proxy_http2();
91-
92-
$frames = $f->{http_start}('/');
93-
($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
94-
$f->{data}('Hello');
95-
$frames = $f->{http_end}();
89+
$frames = $f->{request}('/');
9690
($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
97-
like($frame->{headers}{'x-cache-status'}, qr/HIT/, 'cache test - HIT on cached request');
91+
like($frame->{headers}{'x-cache-status'}, qr/HIT/, 'cache test - HIT on second request');
9892

9993
###############################################################################
10094

@@ -157,20 +151,12 @@ sub proxy_http2 {
157151
$f->{http_end} = sub {
158152
my (%extra) = @_;
159153

160-
# Determine cache status based on request count
161-
my $cache_status = 'MISS';
162-
if ($n > 1) {
163-
$cache_status = 'HIT';
164-
}
165-
166154
my $h = [
167155
{ name => ':status', value => '200',
168156
mode => $extra{mode} || 0 },
169157
{ name => 'content-type', value => 'text/plain',
170158
mode => $extra{mode} || 1, huff => 1 },
171159
{ name => 'x-connection', value => $n,
172-
mode => 2, huff => 1 },
173-
{ name => 'x-cache-status', value => $cache_status,
174160
mode => 2, huff => 1 }];
175161
push @$h, { name => 'content-length', value => $extra{cl} }
176162
if $extra{cl};
@@ -187,11 +173,17 @@ sub proxy_http2 {
187173

188174
return $s->read(all => [{ fin => 1 }]);
189175
};
176+
$f->{request} = sub {
177+
my ($uri) = @_;
178+
$s = Test::Nginx::HTTP2->new() if !defined $s;
179+
my $sid = $s->new_stream({ path => $uri });
180+
return $s->read(all => [{ fin => 1 }]);
181+
};
190182
return $f;
191183
}
192184

193185
sub log2i { Test::Nginx::log_core('|| <<', @_); }
194186
sub log2o { Test::Nginx::log_core('|| >>', @_); }
195187
sub log2c { Test::Nginx::log_core('||', @_); }
196188

197-
###############################################################################
189+
###############################################################################

0 commit comments

Comments
 (0)