25
27
The varnishtest program, when started and given one or more script
26
28
files, can create a number of threads representing backends, some
27
threads representing clients, and a varnishd process.
29
threads representing clients, and a varnishd process. This is then used to
30
simulate a transaction to provoke a specific behavior.
29
32
The following options are available:
31
-n iter Run iter number of iterations.
39
file File to use as a script
34
-D name=val Define macro for use in scripts
36
-i Find varnishd in build tree
38
-j jobs Run this many tests in parallel
40
-k Continue on test failure
42
-l Leave /tmp/vtc.* if test fails
44
-L Always leave /tmp/vtc.*
46
-n iterations Run tests this many times
48
-q Quiet mode: report only failures
50
-t duration Time tests out after this long
52
-v Verbose mode: always report test log
56
file File to use as a script
59
Macro definitions that can be overridden.
61
varnishd Path to varnishd to use [varnishd]
49
# Start a varnish instance called "v1"
50
varnish v1 -arg "-b localhost:9080" -start
52
# Create a server thread called "s1"
56
# Send a standard response
57
txresp -hdr "Connection: close" -body "012345\n"
60
# Start the server thread
63
# Create a client thread called "c1"
69
# Insist that it be a success
70
expect resp.status == 200
76
# Wait for the server to die
79
# (Forcefully) Stop the varnish instance.
85
The output, running this script looks as follows. The "bargraph" at
86
the beginning of the line is an indication of the level of detail in
87
the line. The second field where the message comes from. The rest of
88
the line is anyones guess :-)
91
# TEST tests/b00000.vtc starting
92
### v1 CMD: cd ../varnishd && ./varnishd -d -d -n v1 -a :9081 -T :9001 -b localhost:9080
93
### v1 opening CLI connection
94
#### v1 debug| NB: Storage size limited to 2GB on 32 bit architecture,\n
95
#### v1 debug| NB: otherwise we could run out of address space.\n
96
#### v1 debug| storage_file: filename: ./varnish.Shkoq5 (unlinked) size 2047 MB.\n
97
### v1 CLI connection fd = 3
99
#### v1 debug| Using old SHMFILE\n
100
#### v1 debug| Notice: locking SHMFILE in core failed: Operation not permitted\n
101
#### v1 debug| bind(): Address already in use\n
102
#### v1 debug| rolling(1)...
104
#### v1 debug| rolling(2)...\n
105
#### v1 debug| Debugging mode, enter "start" to start child\n
106
### v1 CLI 200 <start>
107
## s1 Starting server
108
### s1 listen on :9080 (fd 6)
109
## c1 Starting client
110
## c1 Waiting for client
111
## s1 started on :9080
113
### c1 connect to :9081
114
### c1 connected to :9081 fd is 8
115
#### c1 | GET / HTTP/1.1\r\n
118
#### s1 Accepted socket 7
120
#### s1 | GET / HTTP/1.1\r\n
121
#### s1 | X-Varnish: 422080121\r\n
122
#### s1 | X-Forwarded-For: 127.0.0.1\r\n
123
#### s1 | Host: localhost\r\n
125
#### s1 http[ 0] | GET
127
#### s1 http[ 2] | HTTP/1.1
128
#### s1 http[ 3] | X-Varnish: 422080121
129
#### s1 http[ 4] | X-Forwarded-For: 127.0.0.1
130
#### s1 http[ 5] | Host: localhost
131
#### s1 | HTTP/1.1 200 Ok\r\n
132
#### s1 | Connection: close\r\n
137
#### c1 | HTTP/1.1 200 Ok\r\n
138
#### c1 | Content-Length: 9\r\n
139
#### c1 | Date: Mon, 16 Jun 2008 22:16:55 GMT\r\n
140
#### c1 | X-Varnish: 422080121\r\n
142
#### c1 | Via: 1.1 varnish\r\n
143
#### c1 | Connection: keep-alive\r\n
145
#### c1 http[ 0] | HTTP/1.1
146
#### c1 http[ 1] | 200
147
#### c1 http[ 2] | Ok
148
#### c1 http[ 3] | Content-Length: 9
149
#### c1 http[ 4] | Date: Mon, 16 Jun 2008 22:16:55 GMT
150
#### c1 http[ 5] | X-Varnish: 422080121
151
#### c1 http[ 6] | Age: 0
152
#### c1 http[ 7] | Via: 1.1 varnish
153
#### c1 http[ 8] | Connection: keep-alive
154
#### c1 EXPECT resp.status (200) == 200 (200) match
156
## s1 Waiting for server
158
### v1 CLI 200 <stop>
159
# TEST tests/b00000.vtc completed
161
If instead of 200 we had expected 201 with the line:::
163
expect resp.status == 201
165
The output would have ended with:::
167
#### c1 http[ 0] | HTTP/1.1
168
#### c1 http[ 1] | 200
169
#### c1 http[ 2] | Ok
170
#### c1 http[ 3] | Content-Length: 9
171
#### c1 http[ 4] | Date: Mon, 16 Jun 2008 22:26:35 GMT
172
#### c1 http[ 5] | X-Varnish: 648043653 648043652
173
#### c1 http[ 6] | Age: 6
174
#### c1 http[ 7] | Via: 1.1 varnish
175
#### c1 http[ 8] | Connection: keep-alive
176
---- c1 EXPECT resp.status (200) == 201 (201) failed
67
The script language used for Varnishtest is not a strictly defined
68
language. The best reference for writing scripts is the varnishtest program
69
itself. In the Varnish source code repository, under
70
`bin/varnishtest/tests/`, all the regression tests for Varnish are kept.
78
expect req.url == "/bar"
79
txresp -gzipbody {[bar]}
82
expect req.url == "/foo"
83
txresp -body {<h1>FOO<esi:include src="/bar"/>BARF</h1>}
87
varnish v1 -vcl+backend {
89
set beresp.do_esi = true;
90
if (req.url == "/foo") {
99
txreq -url "/bar" -hdr "Accept-Encoding: gzip"
102
expect resp.bodylen == 5
104
txreq -url "/foo" -hdr "Accept-Encoding: gzip"
106
expect resp.bodylen == 21
109
When run, the above script will simulate a server (s1) that expects two
110
different requests. It will start a varnish server (v1) and add the backend
111
definition to the VCL specified (-vcl+backend). Finally it starts the
112
c1-client, which is a single client sending two requests.
117
* varnishtest source code repository with tests