Skip to content
Permalink
Browse files

test VRT_fail from director contexts

Tests #2997
  • Loading branch information...
nigoroll committed May 15, 2019
1 parent 8e7b0f0 commit 0109411b99e0560b99d2daf2327a9f8af03f54d8
Showing with 116 additions and 0 deletions.
  1. +33 −0 bin/varnishtest/tests/d00040.vtc
  2. +6 −0 lib/libvmod_debug/vmod.vcc
  3. +77 −0 lib/libvmod_debug/vmod_debug.c
@@ -0,0 +1,33 @@
varnishtest "Test failing in director callbacks"

varnish v1 -vcl {
import debug;
import std;

backend dummy { .host = "${bad_ip}"; }

sub vcl_init {
new d = debug.director();
}

sub vcl_recv {
if (req.url == "/healthy") {
if (std.healthy(d.fail())) {
return (synth(200));
} else {
return (synth(404));
}
}
set req.backend_hint = d.fail();
}
} -start

client c1 {
txreq -url "/"
rxresp
expect resp.status == 503

txreq -url "/healthy"
rxresp
expect resp.status == 503
} -run
@@ -268,3 +268,9 @@ $Function IP get_ip(PRIV_TASK)

Get the IP address previously stored by ``debug.store_ip()`` in the same
transaction.

$Object director()

$Method BACKEND .fail()

Return a backend which fails in director context
@@ -922,3 +922,80 @@ const struct vmod_data Vmod_wrong3_Data = {
};

//lint -restore

/*---------------------------------------------------------------------*/

struct VPFX(debug_director) {
unsigned magic;
#define VMOD_DEBUG_DIRECTOR_MAGIC 0x66b9ff3d
VCL_BACKEND dir;
};

/* XXX more callbacks ? */
static vdi_healthy_f vmod_debug_director_healthy;
static vdi_resolve_f vmod_debug_director_resolve;

static const struct vdi_methods vmod_debug_director_methods[1] = {{
.magic = VDI_METHODS_MAGIC,
.type = "debug.director",
.resolve = vmod_debug_director_resolve,
.healthy = vmod_debug_director_healthy
}};

VCL_VOID v_matchproto_(td_xyzzy_debug_director__init)
xyzzy_director__init(VRT_CTX, struct VPFX(debug_director) **dp,
const char *vcl_name)
{
struct VPFX(debug_director) *d;

AN(dp);
AZ(*dp);
ALLOC_OBJ(d, VMOD_DEBUG_DIRECTOR_MAGIC);
AN(d);

*dp = d;
d->dir = VRT_AddDirector(ctx, vmod_debug_director_methods, d,
"%s", vcl_name);
}

VCL_VOID v_matchproto_(td_xyzzy_debug_director__fini)
xyzzy_director__fini(struct VPFX(debug_director) **dp)
{
struct VPFX(debug_director) *d;

TAKE_OBJ_NOTNULL(d, dp, VMOD_DEBUG_DIRECTOR_MAGIC);
VRT_DelDirector(&d->dir);
FREE_OBJ(d);
}

VCL_BACKEND v_matchproto_(td_xyzzy_debug_director_fail)
xyzzy_director_fail(VRT_CTX, struct VPFX(debug_director) *d)
{
CHECK_OBJ_NOTNULL(d, VMOD_DEBUG_DIRECTOR_MAGIC);
(void) ctx;

return (d->dir);
}

static VCL_BOOL v_matchproto_(vdi_healthy_f)
vmod_debug_director_healthy(VRT_CTX, VCL_BACKEND dir, VCL_TIME *changed)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);

(void) dir;
(void) changed;

VRT_fail(ctx, "fail");
return (1);
}

static VCL_BACKEND v_matchproto_(vdi_resolve_f)
vmod_debug_director_resolve(VRT_CTX, VCL_BACKEND dir)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);

(void) dir;

VRT_fail(ctx, "fail");
return (NULL);
}

0 comments on commit 0109411

Please sign in to comment.
You can’t perform that action at this time.