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], ...@@ -28,7 +28,7 @@ AC_ARG_WITH([rst2man],
m4_ifndef([VARNISH_PREREQ], AC_MSG_ERROR([Need varnish.m4 -- see README.rst])) 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]) VARNISH_VMODS([weightadjust])
VMOD_TESTS="$(cd $srcdir/src && echo tests/*.vtc)" VMOD_TESTS="$(cd $srcdir/src && echo tests/*.vtc)"
......
...@@ -29,12 +29,12 @@ ...@@ -29,12 +29,12 @@
#include "config.h" #include "config.h"
#include <stdlib.h> #include <stdlib.h>
#include <math.h>
#include "cache/cache.h" #include "cache/cache.h"
#include "cache/cache_director.h" #include "cache/cache_director.h"
#include "vbm.h" #include "vbm.h"
#include "vrnd.h"
#include "vrt.h" #include "vrt.h"
#include "vdir.h" #include "vdir.h"
...@@ -69,7 +69,7 @@ vmod_random_resolve(const struct director *dir, struct worker *wrk, ...@@ -69,7 +69,7 @@ vmod_random_resolve(const struct director *dir, struct worker *wrk,
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_RANDOM_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); assert(r >= 0 && r < 1.0);
be = vdir_pick_be(rr->vd, r, bo); be = vdir_pick_be(rr->vd, r, bo);
return (be); return (be);
......
varnishtest "Deeper test of random director" varnishtest "Deeper test of random director"
random
server s1 { server s1 {
rxreq rxreq
txresp -body "1" txresp -body "1"
rxreq
txresp -body "1"
} -start } -start
server s2 { server s2 {
...@@ -12,17 +12,15 @@ server s2 { ...@@ -12,17 +12,15 @@ server s2 {
txresp -body "22" txresp -body "22"
rxreq rxreq
txresp -body "22" txresp -body "22"
rxreq
txresp -body "22"
rxreq
txresp -body "22"
} -start } -start
server s3 { server s3 {
rxreq rxreq
txresp -body "333" txresp -body "333"
rxreq
txresp -body "333"
rxreq
txresp -body "333"
rxreq
txresp -body "333"
} -start } -start
server s4 { server s4 {
...@@ -30,13 +28,17 @@ server s4 { ...@@ -30,13 +28,17 @@ server s4 {
txresp -body "4444" txresp -body "4444"
rxreq rxreq
txresp -body "4444" txresp -body "4444"
rxreq
txresp -body "4444"
rxreq
txresp -body "4444"
} -start } -start
varnish v1 -vcl+backend { varnish v1 -vcl+backend {
import ${vmod_weightadjust}; import ${vmod_directors};
sub vcl_init { sub vcl_init {
new foo = weightadjust.random(); new foo = directors.random();
foo.add_backend(s1, 1); foo.add_backend(s1, 1);
foo.add_backend(s2, 1); foo.add_backend(s2, 1);
foo.add_backend(s3, 1); foo.add_backend(s3, 1);
...@@ -52,37 +54,40 @@ varnish v1 -vcl+backend { ...@@ -52,37 +54,40 @@ varnish v1 -vcl+backend {
} }
} -start } -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 { client c1 {
txreq txreq
rxresp rxresp
expect resp.bodylen == 3 expect resp.bodylen == 2
txreq txreq
rxresp rxresp
expect resp.bodylen == 4 expect resp.bodylen == 4
txreq txreq
rxresp rxresp
expect resp.bodylen == 1 expect resp.bodylen == 4
txreq txreq
rxresp rxresp
expect resp.bodylen == 1 expect resp.bodylen == 4
txreq txreq
rxresp rxresp
expect resp.bodylen == 2 expect resp.bodylen == 1
txreq txreq
rxresp rxresp
expect resp.bodylen == 2 expect resp.bodylen == 2
txreq txreq
rxresp rxresp
expect resp.bodylen == 3 expect resp.bodylen == 4
txreq txreq
rxresp rxresp
expect resp.bodylen == 4 expect resp.bodylen == 2
txreq txreq
rxresp rxresp
expect resp.bodylen == 3 expect resp.bodylen == 3
txreq txreq
rxresp rxresp
expect resp.bodylen == 3 expect resp.bodylen == 2
} -run } -run
...@@ -72,7 +72,7 @@ vdir_new(struct vdir **vdp, const char *name, const char *vcl_name, ...@@ -72,7 +72,7 @@ vdir_new(struct vdir **vdp, const char *name, const char *vcl_name,
vd->dir->priv = priv; vd->dir->priv = priv;
vd->dir->healthy = healthy; vd->dir->healthy = healthy;
vd->dir->resolve = resolve; vd->dir->resolve = resolve;
vd->vbm = vbit_new(8); vd->vbm = vbit_init(8);
AN(vd->vbm); AN(vd->vbm);
} }
...@@ -81,7 +81,11 @@ vdir_delete(struct vdir **vdp) ...@@ -81,7 +81,11 @@ vdir_delete(struct vdir **vdp)
{ {
struct vdir *vd; 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->backend);
free(vd->weight); free(vd->weight);
......
...@@ -50,15 +50,14 @@ ...@@ -50,15 +50,14 @@
#include "cache/cache.h" #include "cache/cache.h"
#include "vrt.h"
#include "vcl.h" #include "vcl.h"
#include "vrt.h"
#include "vre.h" #include "vre.h"
#include "vsa.h" #include "vsa.h"
#include "vtim.h" #include "vtim.h"
#include "vtcp.h" #include "vtcp.h"
#include "vsb.h" #include "vsb.h"
#include "waiter/waiter.h"
#include "cache/cache_director.h" #include "cache/cache_director.h"
#include "cache/cache_backend.h" #include "cache/cache_backend.h"
......
...@@ -10,7 +10,6 @@ DESCRIPTION ...@@ -10,7 +10,6 @@ DESCRIPTION
=========== ===========
$Event event_function $Event event_function
$Object random(PRIV_VCL) $Object random(PRIV_VCL)
Description Description
......
...@@ -41,14 +41,13 @@ ...@@ -41,14 +41,13 @@
#include "cache/cache.h" #include "cache/cache.h"
#include "vcl.h"
#include "vrt.h" #include "vrt.h"
#include "vre.h" #include "vre.h"
#include "vsa.h" #include "vsa.h"
#include "vtim.h" #include "vtim.h"
#include "vtcp.h" #include "vtcp.h"
#include "vrnd.h"
#include "waiter/waiter.h"
#include "cache/cache_director.h" #include "cache/cache_director.h"
#include "cache/cache_backend.h" #include "cache/cache_backend.h"
...@@ -184,7 +183,7 @@ wadj_update(void *arg) ...@@ -184,7 +183,7 @@ wadj_update(void *arg)
POKE_TRACE(pr, "starting"); POKE_TRACE(pr, "starting");
due.tv_sec = (long)VTIM_real(); 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)); AZ(pthread_mutex_lock(&wa->mtx));
while (pr->run >= STARTING) { 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