blob: 31bb13d368ba1db29ff1a3f8f3ff705d1fe846bb [file]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
meta:
version: "1.0"
# Configuration for the Uranium test runner
urtest:
description: 'Test basic cache operations: miss, hit, no-cache-control, stale, only-if-cached, and max-stale'
dns:
name: 'dns-cache-basic'
server:
name: 'server-cache-basic'
client:
name: 'client-cache-basic'
ats:
name: 'ts-cache-basic'
process_config:
enable_cache: true
plugin_config:
- 'xdebug.so --enable=x-cache,x-cache-key,via'
records_config:
proxy.config.diags.debug.enabled: 1
proxy.config.diags.debug.tags: 'http'
proxy.config.http.response_via_str: 3
proxy.config.http.insert_age_in_response: 0
remap_config:
- from: "http://www.example.com/"
to: "http://backend.example.com:{SERVER_HTTP_PORT}/"
sessions:
- transactions:
#############################################################################
# Test 1: Cache miss - populate cache with max-age=1
#############################################################################
- client-request:
method: GET
url: /cacheable
version: '1.1'
headers:
fields:
- [Host, www.example.com]
- [x-debug, "x-cache,x-cache-key,via"]
- [uuid, cache-miss]
server-response:
status: 200
reason: OK
headers:
fields:
- [Content-Type, text/plain]
- [Content-Length, "3"]
- [Cache-Control, "max-age=1"]
content:
encoding: plain
data: xxx
proxy-response:
status: 200
headers:
fields:
- [Cache-Control, { value: "max-age=1", as: equal }]
- [X-Cache, { value: "miss", as: equal }]
- [X-Cache-Key, { value: "http://", as: contains }]
content:
encoding: plain
data: xxx
verify: { as: equal }
#############################################################################
# Test 2: Cache hit-fresh - retrieve from cache
#############################################################################
- client-request:
delay: 100ms
method: GET
url: /cacheable
version: '1.1'
headers:
fields:
- [Host, www.example.com]
- [x-debug, "x-cache,x-cache-key,via"]
- [uuid, cache-hit]
proxy-request:
expect: absent
# Server should not receive this request (it's cached)
server-response:
status: 404
reason: Not Found
# Expect cached 200 response
proxy-response:
status: 200
headers:
fields:
- [Cache-Control, { value: "max-age=1", as: equal }]
- [X-Cache, { value: "hit-fresh", as: equal }]
content:
encoding: plain
data: xxx
verify: { as: equal }
#############################################################################
# Test 3: No cache-control - response without caching directive (cache miss)
#############################################################################
- client-request:
method: GET
url: /no_cache_control
version: '1.1'
headers:
fields:
- [Host, www.example.com]
- [x-debug, "x-cache,x-cache-key,via"]
- [uuid, no-cache-control]
server-response: &uncacheable-response
status: 200
reason: OK
headers:
fields:
- [Content-Type, text/plain]
- [Content-Length, "14"]
# No Cache-Control header
content:
encoding: plain
data: "the flinstones"
proxy-response:
status: 200
headers:
fields:
- [X-Cache, { value: "miss", as: equal }]
content:
encoding: plain
data: "the flinstones"
verify: { as: equal }
#############################################################################
# Test 4: Explicit client no-cache still reaches the origin
#############################################################################
- client-request:
method: GET
url: /no_cache_control
version: '1.1'
headers:
fields:
- [Host, www.example.com]
- [Cache-Control, no-cache]
- [x-debug, "x-cache,x-cache-key,via"]
- [uuid, client-no-cache]
proxy-request:
headers:
fields:
- [Cache-Control, {value: no-cache, as: equal}]
server-response: *uncacheable-response
proxy-response:
status: 200
headers:
fields:
- [X-Cache, {value: miss, as: equal}]
content:
data: "the flinstones"
verify: {as: equal}
#############################################################################
# Test 5: Hit stale cache - wait for cache entry to become stale
#############################################################################
- client-request:
# Wait for the cache entry from Test 1 to become stale
delay: 2s
method: GET
url: /cacheable
version: '1.1'
headers:
fields:
- [Host, www.example.com]
- [x-debug, "x-cache,x-cache-key,via"]
- [uuid, cache-hit-stale]
# Server should receive revalidation request
server-response:
status: 200
reason: OK
headers:
fields:
- [Content-Type, text/plain]
- [Content-Length, "3"]
- [Cache-Control, "max-age=1"]
content:
encoding: plain
data: xxx
proxy-response:
status: 200
headers:
fields:
- [X-Cache, { value: "hit-stale", as: equal }]
#############################################################################
# Test 6: only-if-cached - should return 504 if not in cache
#############################################################################
- client-request:
method: GET
url: /no_cache_control
version: '1.1'
headers:
fields:
- [Host, www.example.com]
- [Cache-Control, "only-if-cached"]
- [Cache-Control, "max-age=300"]
- [x-debug, "x-cache,x-cache-key,via"]
- [uuid, only-if-cached]
proxy-request:
expect: absent
# Server should not be contacted for only-if-cached requests
server-response:
status: 200
reason: OK
# Should get 504 Not Cached
proxy-response:
status: 504
reason: "Not Cached"
headers:
fields:
- [X-Cache, { value: "miss", as: equal }]
- [Cache-Control, { value: "no-store", as: equal }]
#############################################################################
# Test 6: Populate an entry for a valueless max-stale request
#############################################################################
- client-request:
method: GET
url: /max-stale
version: '1.1'
headers:
fields:
- [Host, www.example.com]
- [x-debug, "x-cache,x-cache-key,via"]
- [uuid, max-stale-populate]
server-response:
status: 200
reason: OK
headers:
fields:
- [Content-Type, text/plain]
- [Content-Length, "5"]
# max-age=0 makes the cached response stale immediately.
- [Cache-Control, "max-age=0"]
content:
encoding: plain
data: stale
proxy-response:
status: 200
headers:
fields:
- [X-Cache, { value: "miss", as: equal }]
content:
encoding: plain
data: stale
verify: { as: equal }
#############################################################################
# Test 7: Valueless max-stale permits serving a stale response of any age
#############################################################################
- client-request:
# Allow the cache write from the preceding transaction to finish.
delay: 100ms
method: GET
url: /max-stale
version: '1.1'
headers:
fields:
- [Host, www.example.com]
- [Cache-Control, "max-stale"]
- [x-debug, "x-cache,x-cache-key,via"]
- [uuid, max-stale-serve]
proxy-request:
expect: absent
# The server response is a sentinel and must not be used.
server-response:
status: 502
reason: Bad Gateway
proxy-response:
status: 200
headers:
fields:
# ATS reports an acceptable-stale lookup as a fresh cache hit.
- [X-Cache, { value: "hit-fresh", as: equal }]
content:
encoding: plain
data: stale
verify: { as: equal }