File: async.test

package info (click to toggle)
tcllib 2.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 83,560 kB
  • sloc: tcl: 306,798; ansic: 14,272; sh: 3,035; xml: 1,766; yacc: 1,157; pascal: 881; makefile: 124; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (259 lines) | stat: -rw-r--r-- 5,097 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# -*- tcl -*-
# Tests for the cache::async module.
#
# Copyright (c) 2008 Andreas Kupries <andreas_kupries@users.sourceforge.net>
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: async.test,v 1.1 2008/11/19 06:04:59 andreas_kupries Exp $

# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.5
testsNeedTcltest 2.0

testing {
    useLocal async.tcl cache::async
}

# -------------------------------------------------------------------------
# Helper commands

proc DATA_NONE {method key cmd} {
    res+ DATA_NONE $method $key $cmd
    set ::wait .
    return -code error "Should not be called"
}

proc DATA_VALUE {method key cmd} {
    res+ DATA_VALUE $method $key $cmd
    eval [linsert $cmd end set $key ALPHA]
    return
}

proc DATA_HOLE {method key cmd} {
    res+ DATA_HOLE $method $key $cmd
    eval [linsert $cmd end unset $key]
    return
}

proc DONE {args} {
    res+ DONE $args
    set ::wait .
    return
}

proc WAIT {} {
    res+ WAIT
    vwait ::wait
    res+ RESUME
}

# -------------------------------------------------------------------------

test cache-async-1.0 {preset value} -setup {
    cache::async ca DATA_NONE
    ca set KEY VALUE
    res!
} -body {
    res+ BEGIN
    ca get KEY DONE
    WAIT
    res?lines
} -cleanup {
    ca destroy
} -result {BEGIN
WAIT
DONE {set KEY VALUE}
RESUME}

test cache-async-1.1 {preset hole} -setup {
    cache::async ca DATA_NONE
    ca unset KEY
    res!
} -body {
    res+ BEGIN
    ca get KEY DONE
    WAIT
    res?lines
} -cleanup {
    ca destroy
} -result {BEGIN
WAIT
DONE {unset KEY}
RESUME}

# -------------------------------------------------------------------------

test cache-async-2.0 {provider value} -setup {
    cache::async ca DATA_VALUE
    res!
} -body {
    res+ BEGIN
    ca get KEY DONE
    WAIT
    res?lines
} -cleanup {
    ca destroy
} -result {BEGIN
WAIT
DATA_VALUE get KEY ::ca
DONE {set KEY ALPHA}
RESUME}

test cache-async-2.1 {provider hole} -setup {
    cache::async ca DATA_HOLE
    res!
} -body {
    res+ BEGIN
    ca get KEY DONE
    WAIT
    res?lines
} -cleanup {
    ca destroy
} -result {BEGIN
WAIT
DATA_HOLE get KEY ::ca
DONE {unset KEY}
RESUME}

# -------------------------------------------------------------------------

test cache-async-3.0 {provider value, multi request merge} -setup {
    cache::async ca DATA_VALUE
    res!
} -body {
    res+ BEGIN
    ca get KEY DONE
    ca get KEY DONE
    ca get KEY DONE
    WAIT
    res?lines
} -cleanup {
    ca destroy
} -result {BEGIN
WAIT
DATA_VALUE get KEY ::ca
DONE {set KEY ALPHA}
DONE {set KEY ALPHA}
DONE {set KEY ALPHA}
RESUME}

test cache-async-3.1 {provider hole, multi request merge} -setup {
    cache::async ca DATA_HOLE
    res!
} -body {
    res+ BEGIN
    ca get KEY DONE
    ca get KEY DONE
    ca get KEY DONE
    WAIT
    res?lines
} -cleanup {
    ca destroy
} -result {BEGIN
WAIT
DATA_HOLE get KEY ::ca
DONE {unset KEY}
DONE {unset KEY}
DONE {unset KEY}
RESUME}

# -------------------------------------------------------------------------

test cache-async-4.0 {preset value, sync return on hit} -setup {
    cache::async ca DATA_NONE -full-async-results 0
    ca set KEY VALUE
    res!
} -body {
    res+ BEGIN
    ca get KEY DONE
    res?lines
} -cleanup {
    ca destroy
} -result {BEGIN
DONE {set KEY VALUE}}

test cache-async-4.1 {preset hole, sync return on hit} -setup {
    cache::async ca DATA_NONE -full-async-results 0
    ca unset KEY
    res!
} -body {
    res+ BEGIN
    ca get KEY DONE
    res?lines
} -cleanup {
    ca destroy
} -result {BEGIN
DONE {unset KEY}}

# -------------------------------------------------------------------------

test cache-async-5.0 {provider value, stays async} -setup {
    cache::async ca DATA_VALUE -full-async-results 0
    res!
} -body {
    res+ BEGIN
    ca get KEY DONE
    WAIT
    res?lines
} -cleanup {
    ca destroy
} -result {BEGIN
WAIT
DATA_VALUE get KEY ::ca
DONE {set KEY ALPHA}
RESUME}

test cache-async-5.1 {provider hole, stays async} -setup {
    cache::async ca DATA_HOLE -full-async-results 0
    res!
} -body {
    res+ BEGIN
    ca get KEY DONE
    WAIT
    res?lines
} -cleanup {
    ca destroy
} -result {BEGIN
WAIT
DATA_HOLE get KEY ::ca
DONE {unset KEY}
RESUME}

# -- $obj clear ---------------------------------------------------------------

test cache-async-6.0 {clear a not existing value} -setup {
    cache::async ca DATA_NONE
    res!
} -body {
    res+ BEGIN
    ca clear KEY
    res+ END
    res?lines
} -cleanup {
    ca destroy
} -result {BEGIN
END}

test cache-async-6.1 {clear an existing value} -setup {
    cache::async ca DATA_NONE
    ca set KEY VALUE
    res!
} -body {
    res+ BEGIN
    ca clear KEY
    res+ END
    res?lines
} -cleanup {
    ca destroy
} -result {BEGIN
END}

# -------------------------------------------------------------------------
testsuiteCleanup