Commit e41f4705 authored by Nils Goroll's avatar Nils Goroll

4.1 backport

parent cf0a7cc3
Pipeline #308 skipped
......@@ -28,7 +28,7 @@ AC_ARG_WITH([rst2man],
m4_ifndef([VARNISH_PREREQ], AC_MSG_ERROR([Need varnish.m4 -- see README.rst]))
VARNISH_PREREQ([5.2])
VARNISH_PREREQ([4.1],[5.2])
VARNISH_VMODS([weightadjust])
VMOD_TESTS="$(cd $srcdir/src && echo tests/*.vtc)"
......
......@@ -29,12 +29,12 @@
#include "config.h"
#include <stdlib.h>
#include <math.h>
#include "cache/cache.h"
#include "cache/cache_director.h"
#include "vbm.h"
#include "vrnd.h"
#include "vrt.h"
#include "vdir.h"
......@@ -69,7 +69,7 @@ vmod_random_resolve(const struct director *dir, struct worker *wrk,
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_RANDOM_MAGIC);
r = scalbn(VRND_RandomTestable(), -31);
r = scalbn(random(), -31);
assert(r >= 0 && r < 1.0);
be = vdir_pick_be(rr->vd, r, bo);
return (be);
......
varnishtest "Deeper test of random director"
random
server s1 {
rxreq
txresp -body "1"
rxreq
txresp -body "1"
} -start
server s2 {
......@@ -12,17 +12,15 @@ server s2 {
txresp -body "22"
rxreq
txresp -body "22"
rxreq
txresp -body "22"
rxreq
txresp -body "22"
} -start
server s3 {
rxreq
txresp -body "333"
rxreq
txresp -body "333"
rxreq
txresp -body "333"
rxreq
txresp -body "333"
} -start
server s4 {
......@@ -30,13 +28,17 @@ server s4 {
txresp -body "4444"
rxreq
txresp -body "4444"
rxreq
txresp -body "4444"
rxreq
txresp -body "4444"
} -start
varnish v1 -vcl+backend {
import ${vmod_weightadjust};
import ${vmod_directors};
sub vcl_init {
new foo = weightadjust.random();
new foo = directors.random();
foo.add_backend(s1, 1);
foo.add_backend(s2, 1);
foo.add_backend(s3, 1);
......@@ -52,37 +54,40 @@ varnish v1 -vcl+backend {
}
} -start
varnish v1 -cliok "debug.srandom"
# NB: Do not change the number 1
# NB: Only srandom(1) is standardized as deterministic.
varnish v1 -cliok "debug.srandom 1"
client c1 {
txreq
rxresp
expect resp.bodylen == 3
expect resp.bodylen == 2
txreq
rxresp
expect resp.bodylen == 4
txreq
rxresp
expect resp.bodylen == 1
expect resp.bodylen == 4
txreq
rxresp
expect resp.bodylen == 1
expect resp.bodylen == 4
txreq
rxresp
expect resp.bodylen == 2
expect resp.bodylen == 1
txreq
rxresp
expect resp.bodylen == 2
txreq
rxresp
expect resp.bodylen == 3
expect resp.bodylen == 4
txreq
rxresp
expect resp.bodylen == 4
expect resp.bodylen == 2
txreq
rxresp
expect resp.bodylen == 3
txreq
rxresp
expect resp.bodylen == 3
expect resp.bodylen == 2
} -run
......@@ -72,7 +72,7 @@ vdir_new(struct vdir **vdp, const char *name, const char *vcl_name,
vd->dir->priv = priv;
vd->dir->healthy = healthy;
vd->dir->resolve = resolve;
vd->vbm = vbit_new(8);
vd->vbm = vbit_init(8);
AN(vd->vbm);
}
......@@ -81,7 +81,11 @@ vdir_delete(struct vdir **vdp)
{
struct vdir *vd;
TAKE_OBJ_NOTNULL(vd, vdp, VDIR_MAGIC);
AN(vdp);
vd = *vdp;
*vdp = NULL;
CHECK_OBJ_NOTNULL(vd, VDIR_MAGIC);
free(vd->backend);
free(vd->weight);
......
......@@ -50,15 +50,14 @@
#include "cache/cache.h"
#include "vrt.h"
#include "vcl.h"
#include "vrt.h"
#include "vre.h"
#include "vsa.h"
#include "vtim.h"
#include "vtcp.h"
#include "vsb.h"
#include "waiter/waiter.h"
#include "cache/cache_director.h"
#include "cache/cache_backend.h"
......
......@@ -10,7 +10,6 @@ DESCRIPTION
===========
$Event event_function
$Object random(PRIV_VCL)
Description
......
......@@ -41,14 +41,13 @@
#include "cache/cache.h"
#include "vcl.h"
#include "vrt.h"
#include "vre.h"
#include "vsa.h"
#include "vtim.h"
#include "vtcp.h"
#include "vrnd.h"
#include "waiter/waiter.h"
#include "cache/cache_director.h"
#include "cache/cache_backend.h"
......@@ -184,7 +183,7 @@ wadj_update(void *arg)
POKE_TRACE(pr, "starting");
due.tv_sec = (long)VTIM_real();
due.tv_nsec = 1e9 * VRND_RandomTestableDouble();
due.tv_nsec = 1e9 * (double)random() / (double)RAND_MAX;
AZ(pthread_mutex_lock(&wa->mtx));
while (pr->run >= STARTING) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment