varnish-4.x
VTL--varnishtest
The Varnish Test Case (VTC) Language
• Test against simulated or real backends
• Starts real instance of varnishd
• Simulates clients
• Asserts using expect
如下:是一个测试例子,保存为foo.vtc
varnishtest "Varnish as Proxy"
server s1 {
} -start
server s2 {
}
server s2
start
varnish v1 -arg "-b
192.168.192.10:8080" -start
varnish v2 -arg "-b ${s1_addr}:${s1_port}"
-start
client c1 {
} -run
client c2 {
} -run
client c3 {
}
client c3 run
1.VTC程序都以test命名开头
varnishtest "Varnish as Proxy"
2.定义模拟若干真实的后端origin server
s1,s2等命名都必须以s开头,字面意思上就可以看出,s1,s2接受一个请求rxreq,传输应答txresp,${s1_addr}:${s1_port}定义后端server的地址和端口,可以是真实的后端地址及端口,server启动可简写可新行完整申明
3.定义模拟若干varnish server
4.定义模拟若干client
varnish是完全为现代硬件架构和操作系统设计,多线程,所以几个角色(server,varnish,client)可能启动先后顺序会有一定影响,所以又提供了-wait参数
-run
-start
-wait
有兴趣的朋友可以试下如下,VTL
示例2
varnishtest "Synchronized"
server s1 {
}
server s1 -start
client c1 -connect ${s1_sock} {
}
# -run: -start - wait
client c1 -run
server s1 -wait
示例3
varnishtest "Unsynchronized"
server s1 {
}
server s1 -start -wait
client c1 -connect ${s1_sock} {
}
client c1 -run
root@config-p:~#varnishtest t2.vtc
**** top 0.0 macro def
varnishd=varnishd
**** top 0.0 macro def
varnishadm=varnishadm
**** top 0.0 macro def
varnishstat=varnishstat
**** top 0.0 macro def
varnishhist=varnishhist
**** top 0.0 macro def
varnishlog=varnishlog
**** top 0.0 macro def
varnishncsa=varnishncsa
**** top 0.0 macro def vmod_std=std
**** top 0.0 macro def
vmod_debug=debug
**** top 0.0 macro def
vmod_directors=directors
**** top 0.0 macro def pwd=/root
**** top 0.0 macro def
bad_ip=192.0.2.255
**** top 0.0 macro def
tmpdir=/tmp/vtc.84399.1a833cf5
* top
0.0 TEST t2.vtc starting
*** top 0.0
varnishtest
* top
0.0 TEST Unsynchronized
*** top 0.0 server
*** top 0.0 server
** s1
0.0 Starting server
**** s1 0.0 macro def
s1_addr=127.0.0.1
**** s1 0.0 macro def
s1_port=36877
**** s1 0.0
macro def s1_sock=127.0.0.1 36877
* s1
0.0 Listen on 127.0.0.1 36877
** s1
0.0 Waiting for server
** s1
0.0 Started on 127.0.0.1 36877
# top
TEST t2.vtc FAILED (60.007) signal=9 exit=0
失败是因为等待s1返回超时
测试命令
varnishtest foo.vtc [-v]