source: project/wiki/eggref/4/server-test @ 31108

Last change on this file since 31108 was 31108, checked in by arthurmaciel, 6 years ago

Corrected the example.

File size: 4.5 KB
Line 
1== server-test
2
3[[toc:]]
4
5=== Description
6
7Utilities to help testing servers
8
9=== Author
10
11[[/users/mario-domenech-goulart|Mario Domenech Goulart]]
12
13
14=== Repository
15
16[[https://github.com/mario-goulart/server-test|https://github.com/mario-goulart/server-test]]
17
18
19=== Parameters
20
21==== test-server-port
22
23<parameter>(test-server-port [integer])</parameter>
24
25The port to access the test server.  The default value is {{8080}}.
26
27==== connect-procedure
28
29<parameter>(connect-procedure [procedure])</parameter>
30
31The procedure to be used to check if the server is ready to accept
32requests.  Default is {{tcp-connect}} from
33[[/man/4/Unit tcp|unit tcp]].
34
35
36==== standby-time
37<parameter>(standby-time [integer])</parameter>
38
39Time in seconds to wait for the server to start serving after it has
40started accepting connections.  This parameter was introduced in
41version 0.4.
42
43
44==== max-attempts-to-connect
45<parameter>(max-attempts-to-connect [integer])</parameter>
46
47Maximum number of attempts to connect to the server before assuming
48that it failed to start. This parameter was introduced in version 0.4.
49
50
51==== time-between-attempts-to-connect
52<parameter>(time-between-attempts-to-connect [integer])</parameter>
53
54Time in seconds to wait between to consecutive attempts to connect to
55the server. This parameter was introduced in version 0.4.
56
57
58=== Procedures
59
60==== High level interface
61
62===== with-test-server
63<procedure>(with-test-server server-thunk tests-thunk)</procedure>
64
65Start the server by executing {{server-thunk}}, run the tests
66({{tests-thunk}}) and stop the server.
67
68Here's a usage example with the [[/egg/awful|awful]],
69[[/egg/test|test]] and [[/egg/http-client|http-client]] eggs:
70
71The awful application to be tested:
72
73<enscript highlight=scheme>
74(use awful)
75
76(define-page "/foo"
77  (lambda ()
78    "foo")
79  no-template: #t)
80</enscript>
81
82The test program:
83
84<enscript highlight=scheme>
85(use server-test awful http-client test)
86
87;; The awful application to be tested
88(awful-apps (list "foo.scm"))
89
90(with-test-server
91 (lambda ()
92   (awful-start
93    (lambda ()
94      (load-apps (awful-apps)))))
95 (lambda ()   
96   (test "foo"
97         (with-input-from-request "http://localhost:8080/foo"
98                                  #f
99                                  read-string))))
100</enscript>
101
102
103==== Low level interface
104
105===== start-test-server
106<procedure>(start-test-server thunk)</procedure>
107
108Start the test server and returns its pid.  {{thunk}} is the procedure
109which actually runs the server.
110
111
112===== stop-test-server
113<procedure>(stop-server pid)</procedure>
114
115Stops the server whose pid is the given {{pid}}.
116
117
118
119=== License
120
121 Copyright (c) 2012 Mario Domenech Goulart
122 All rights reserved.
123 
124 Redistribution and use in source and binary forms, with or without
125 modification, are permitted provided that the following conditions are
126 met:
127 
128 Redistributions of source code must retain the above copyright
129 notice, this list of conditions and the following disclaimer.
130 
131 Redistributions in binary form must reproduce the above copyright
132 notice, this list of conditions and the following disclaimer in the
133 documentation and/or other materials provided with the distribution.
134 
135 Neither the name of the author nor the names of its contributors may
136 be used to endorse or promote products derived from this software
137 without specific prior written permission.
138 
139 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
140 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
141 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
142 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
143 COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
144 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
145 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
146 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
147 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
148 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
149 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
150 OF THE POSSIBILITY OF SUCH DAMAGE.
151
152
153
154=== Version history
155
156===== version 0.5
157
158* Bug fix: propagate exceptions raised when running tests code
159
160
161===== version 0.4
162
163* Add {{standby-time}}, {{max-attempts-to-connect}} and {{time-between-attempts-to-connect}} parameters
164
165
166===== version 0.3
167
168* Fixed release numbers/tags (thanks to Peter Bex)
169
170
171===== version 0.2
172
173* Bug fix in the internal {{can-connect?}} procedure (it was not honoring {{test-server-port}})
174
175
176===== version 0.1
177
178* Initial release
Note: See TracBrowser for help on using the repository browser.