aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-07-21 15:30:15 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-07-21 19:44:58 +0300
commitd06b3136f1c52480a9f1c5aa3d38cf557bd7e3e5 (patch)
tree462efb0904237d4b84166f813cc04edbcb34a5ca /tests
downloadvmod-tbf-d06b3136f1c52480a9f1c5aa3d38cf557bd7e3e5.tar.gz
vmod-tbf-d06b3136f1c52480a9f1c5aa3d38cf557bd7e3e5.tar.bz2
Initial commit
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am14
-rw-r--r--tests/test00.vtc47
-rw-r--r--tests/test01.vtc59
3 files changed, 120 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..4ae5ec2
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,14 @@
+VMOD_TESTS = \
+ test00.vtc\
+ test01.vtc
+
+EXTRA_DIST=$(VMOD_TESTS)
+DISTCLEANFILES=tbf.db
+check:
+ cd $(abs_srcdir); \
+ for t in $(VMOD_TESTS); do \
+ $(VARNISHSRC)/bin/varnishtest/varnishtest \
+ -Dvarnishd=$(VARNISHSRC)/bin/varnishd/varnishd \
+ -Dvmod_topsrc=$(abs_top_srcdir) \
+ -Dvmod_topbuild=$(abs_top_builddir) $$t; \
+ done
diff --git a/tests/test00.vtc b/tests/test00.vtc
new file mode 100644
index 0000000..10f99ca
--- /dev/null
+++ b/tests/test00.vtc
@@ -0,0 +1,47 @@
+varnishtest "Test tbf overlimit"
+
+server s1 {
+ rxreq
+ txresp
+} -start
+
+varnish v1 -vcl+backend {
+ import tbf from "${vmod_topbuild}/src/.libs/libvmod_tbf.so";
+ sub vcl_init {
+ tbf.open("${vmod_topbuild}/tests/tbf.db", "truncate");
+ }
+ sub vcl_fini {
+ tbf.close();
+ }
+ sub vcl_recv {
+ if (!tbf.rate("url:"+req.url, 1, 20 s, 5)) {
+ error 420 "Overlimit";
+ }
+ return (lookup);
+ }
+} -start
+
+client c1 {
+ txreq -url "/"
+ rxresp
+ expect resp.status == 200
+ txreq -url "/"
+ rxresp
+ expect resp.status == 200
+ txreq -url "/"
+ rxresp
+ expect resp.status == 200
+ txreq -url "/"
+ rxresp
+ expect resp.status == 200
+ txreq -url "/"
+ rxresp
+ expect resp.status == 200
+ txreq -url "/"
+ rxresp
+ expect resp.status == 420
+}
+
+client c1 -run
+
+
diff --git a/tests/test01.vtc b/tests/test01.vtc
new file mode 100644
index 0000000..ad6f7d1
--- /dev/null
+++ b/tests/test01.vtc
@@ -0,0 +1,59 @@
+varnishtest "Test tbf flow"
+
+server s1 {
+ rxreq
+ txresp
+} -start
+
+varnish v1 -vcl+backend {
+ import tbf from "${vmod_topbuild}/src/.libs/libvmod_tbf.so";
+ sub vcl_init {
+ tbf.open("${vmod_topbuild}/tests/tbf.db", "trunc");
+ }
+ sub vcl_fini {
+ tbf.close();
+ }
+ sub vcl_deliver {
+ set resp.http.result = tbf.rate("url:"+req.url, 1, 1s, 5);
+ }
+} -start
+
+client c1 {
+ txreq -url "/"
+ rxresp
+ expect resp.http.result == true
+
+ txreq -url "/"
+ rxresp
+ expect resp.http.result == true
+
+ txreq -url "/"
+ rxresp
+ expect resp.http.result == true
+
+ txreq -url "/"
+ rxresp
+ expect resp.http.result == true
+
+ txreq -url "/"
+ rxresp
+ expect resp.http.result == true
+
+ txreq -url "/"
+ rxresp
+ expect resp.http.result == false
+
+ delay 1.0
+
+ txreq -url "/"
+ rxresp
+ expect resp.http.result == true
+
+ txreq -url "/"
+ rxresp
+ expect resp.http.result == false
+}
+
+client c1 -run
+
+

Return to:

Send suggestions and report system problems to the System administrator.