mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-19 01:54:37 +00:00
e1465c1e46
Some regtests involve multiple requests from multiple clients, which can be dispatched as multiple requests to a server. It turns out that the idle connection sharing works so well that very quickly few connections are used, and regularly some of the remaining idle server connections time out at the moment they were going to be reused, causing those random "HTTP header incomplete" traces in the logs that make them fail often. In the end this is only an artefact of the test environment. And indeed, some tests like normalize-uri which perform a lot of reuse fail very often, about 20-30% of the times in the CI, and 100% of the time in local when running 1000 tests in a row. Others like ubase64, sample_fetches or vary_* fail less often but still a lot in tests. This patch addresses this by adding "tune.idle-pool.shared off" to all tests which have at least twice as many requests as clients. It proves very effective as no single error happens on normalize-uri anymore after 10000 tests. Also 100 full runs of all tests yield no error anymore. One test is tricky, http_abortonclose, it used to fail ~10 times per 1000 runs and with this workaround still fails once every 1000 runs. But the test is complex and there's a warning in it mentioning a possible issue when run in parallel due to a port reuse.
226 lines
5.7 KiB
Plaintext
226 lines
5.7 KiB
Plaintext
varnishtest "Caching rules test"
|
|
# A response will not be cached unless it has an explicit age (Cache-Control max-age of s-maxage, Expires) or a validator (Last-Modified, or ETag)
|
|
# A response will not be cached either if it has an Age header that is either invalid (should be an integer) or greater than its max age.
|
|
|
|
#REQUIRE_VERSION=2.4
|
|
|
|
feature ignore_unknown_macro
|
|
|
|
server s1 {
|
|
rxreq
|
|
expect req.url == "/max-age"
|
|
txresp -hdr "Cache-Control: max-age=5" \
|
|
-bodylen 150
|
|
|
|
rxreq
|
|
expect req.url == "/s-maxage"
|
|
txresp -hdr "Cache-Control: s-maxage=5" \
|
|
-bodylen 160
|
|
|
|
rxreq
|
|
expect req.url == "/last-modified"
|
|
txresp -hdr "Last-Modified: Thu, 22 Oct 2020 16:51:12 GMT" \
|
|
-bodylen 180
|
|
|
|
rxreq
|
|
expect req.url == "/etag"
|
|
txresp -hdr "ETag: \"etag\"" \
|
|
-bodylen 190
|
|
|
|
rxreq
|
|
expect req.url == "/uncacheable"
|
|
txresp \
|
|
-bodylen 200
|
|
|
|
rxreq
|
|
expect req.url == "/uncacheable"
|
|
txresp \
|
|
-bodylen 210
|
|
|
|
# Age response header checks
|
|
|
|
# Invalid age
|
|
rxreq
|
|
expect req.url == "/invalid_age"
|
|
txresp -hdr "Cache-Control: max-age=5" \
|
|
-hdr "Age: abc" -bodylen 120
|
|
|
|
rxreq
|
|
expect req.url == "/invalid_age"
|
|
txresp -hdr "Cache-Control: max-age=5" \
|
|
-hdr "Age: abc" -bodylen 120
|
|
|
|
# Old age (greater than max age)
|
|
rxreq
|
|
expect req.url == "/old_age"
|
|
txresp -hdr "Cache-Control: max-age=5" \
|
|
-hdr "Age: 10" -bodylen 130
|
|
|
|
rxreq
|
|
expect req.url == "/old_age"
|
|
txresp -hdr "Cache-Control: max-age=5" \
|
|
-hdr "Age: 10" -bodylen 130
|
|
|
|
# Good age
|
|
rxreq
|
|
expect req.url == "/good_age"
|
|
txresp -hdr "Cache-Control: max-age=500" \
|
|
-hdr "Age: 100" -bodylen 140
|
|
|
|
} -start
|
|
|
|
server s2 {
|
|
rxreq
|
|
expect req.url == "/expires"
|
|
# Expires header is filled directly by the expires_be backend"
|
|
txresp \
|
|
-bodylen 170
|
|
} -start
|
|
|
|
haproxy h1 -conf {
|
|
global
|
|
# WT: limit false-positives causing "HTTP header incomplete" due to
|
|
# idle server connections being randomly used and randomly expiring
|
|
# under us.
|
|
tune.idle-pool.shared off
|
|
|
|
defaults
|
|
mode http
|
|
${no-htx} option http-use-htx
|
|
timeout connect 1s
|
|
timeout client 1s
|
|
timeout server 1s
|
|
|
|
frontend fe
|
|
bind "fd@${fe}"
|
|
use_backend expires_be if { path_beg /expires }
|
|
default_backend test
|
|
|
|
backend expires_be
|
|
http-request cache-use my_cache
|
|
server www ${s2_addr}:${s2_port}
|
|
http-response set-header X-Cache-Hit %[res.cache_hit]
|
|
# Expires value set in the future (current_time+5s)
|
|
http-response set-header Expires %[date(5),http_date]
|
|
http-response cache-store my_cache
|
|
|
|
backend test
|
|
http-request cache-use my_cache
|
|
server www ${s1_addr}:${s1_port}
|
|
http-response cache-store my_cache
|
|
http-response set-header X-Cache-Hit %[res.cache_hit]
|
|
|
|
cache my_cache
|
|
total-max-size 3
|
|
max-age 20
|
|
max-object-size 3072
|
|
} -start
|
|
|
|
|
|
client c1 -connect ${h1_fe_sock} {
|
|
txreq -url "/max-age"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 150
|
|
|
|
txreq -url "/max-age"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 150
|
|
expect resp.http.X-Cache-Hit == 1
|
|
|
|
txreq -url "/s-maxage"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 160
|
|
|
|
txreq -url "/s-maxage"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 160
|
|
expect resp.http.X-Cache-Hit == 1
|
|
|
|
txreq -url "/expires"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 170
|
|
|
|
txreq -url "/expires"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 170
|
|
expect resp.http.X-Cache-Hit == 1
|
|
|
|
txreq -url "/last-modified"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 180
|
|
|
|
txreq -url "/last-modified"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 180
|
|
expect resp.http.X-Cache-Hit == 1
|
|
|
|
txreq -url "/etag"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 190
|
|
|
|
txreq -url "/etag"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 190
|
|
expect resp.http.X-Cache-Hit == 1
|
|
|
|
# The next response should not be cached
|
|
txreq -url "/uncacheable"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 200
|
|
|
|
txreq -url "/uncacheable"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 210
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
# Age header tests
|
|
txreq -url "/invalid_age"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 120
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
txreq -url "/invalid_age"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 120
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
txreq -url "/old_age"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 130
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
txreq -url "/old_age"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 130
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
txreq -url "/good_age"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 140
|
|
expect resp.http.X-Cache-Hit == 0
|
|
|
|
txreq -url "/good_age"
|
|
rxresp
|
|
expect resp.status == 200
|
|
expect resp.bodylen == 140
|
|
expect resp.http.X-Cache-Hit == 1
|
|
|
|
} -run
|