Created
November 4, 2014 16:13
-
-
Save LukasMac/f2fc96d4686d97c71c5e to your computer and use it in GitHub Desktop.
Varnish test: unhealthy backend responds with cached content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
varnishtest "Unhealthy Fnord responds with cached content" | |
# fnord. fake server name must start with "s" | |
server s1 { | |
rxreq | |
expect req.url == "/platform/test" | |
txresp -hdr "Content-Type: application/vnd.itv.ctv.production.v1+hal+json; charset=UTF-8" -hdr "Vary: Accept" -body "{\"hello\": \"world\"}" | |
accept | |
} -start | |
# catchall fake server for all other microservices | |
server s2 { | |
rxreq | |
txresp -body "request 1" | |
} -start | |
varnish v1 -vcl { | |
import ${vmod_directors}; | |
import ${vmod_std}; | |
# Declare fake fnord backend | |
backend fnord_localhost { | |
.host = "${s1_addr}"; | |
.port = "${s1_port}"; | |
} | |
# Declare a fake catchall backend for stuff we dont care about in this test | |
backend catchall_localhost { | |
.host = "${s2_addr}"; | |
.port = "${s2_port}"; | |
} | |
# Actual config requires a backend called "dummy": get from actual config | |
include "/etc/varnish/dummy.vcl"; | |
# Add all director clusters that use the fake backends above. Note that the cluster names are referenced in VCL config | |
sub vcl_init { | |
new fnord = directors.round_robin(); | |
fnord.add_backend(fnord_localhost); | |
# dont care about these for the fnord tests | |
new dawkins_query = directors.round_robin(); | |
dawkins_query.add_backend(catchall_localhost); | |
new goggins = directors.round_robin(); | |
goggins.add_backend(catchall_localhost); | |
new minerva = directors.round_robin(); | |
minerva.add_backend(catchall_localhost); | |
new rmqcps = directors.round_robin(); | |
rmqcps.add_backend(catchall_localhost); | |
new venus = directors.round_robin(); | |
venus.add_backend(catchall_localhost); | |
new vogue_query = directors.round_robin(); | |
vogue_query.add_backend(catchall_localhost); | |
} | |
# Add the VCL config under test | |
include "/etc/varnish/sites.d/dev-api.itv.com.vcl"; | |
} -start | |
# Make fnord backend healthy | |
varnish v1 -cliok "backend.set_health fnord_localhost healthy" | |
# This request should hit backend | |
client c1 { | |
txreq -url "/platform/test" -hdr "Accept: application/vnd.itv.ctv.production.v1+hal+json" | |
rxresp | |
expect resp.status == 200 | |
expect resp.bodylen == 18 | |
} -run | |
# Make fnord backend sick | |
varnish v1 -cliok "backend.set_health fnord_localhost sick" | |
# This request should come from varnish cache | |
client c1 { | |
txreq -url "/platform/test" -hdr "Accept: application/vnd.itv.ctv.production.v1+hal+json" | |
rxresp | |
expect resp.status == 200 | |
expect resp.bodylen == 18 | |
} -run | |
varnish v1 -expect client_req == 2 | |
varnish v1 -expect cache_hit == 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment