0
|
1 |
"{ NameSpace: RegressionTests }"
|
|
2 |
|
|
3 |
Object subclass:#FileStreamTest
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
1
|
7 |
category:'Tests - Streams'
|
0
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!FileStreamTest class methodsFor:'tests'!
|
|
12 |
|
|
13 |
createTestFile
|
|
14 |
"create a test file (100k size)"
|
|
15 |
|
|
16 |
|f bytes|
|
|
17 |
|
|
18 |
f := 'testFile' asFilename writeStream binary.
|
|
19 |
bytes := ByteArray new:1024.
|
|
20 |
1 to:bytes size do:[:i |
|
1
|
21 |
bytes at:i put:(i \\ 256).
|
0
|
22 |
].
|
|
23 |
|
|
24 |
100 timesRepeat:[
|
1
|
25 |
f nextPutAll:bytes.
|
0
|
26 |
].
|
|
27 |
|
|
28 |
f close.
|
|
29 |
|
|
30 |
"
|
|
31 |
self createTestFile
|
|
32 |
"
|
|
33 |
|
|
34 |
"Created: / 12.8.1998 / 13:25:25 / cg"
|
|
35 |
!
|
|
36 |
|
|
37 |
readFileExpecting:expect
|
|
38 |
"read test file, expect n bytes"
|
|
39 |
|
|
40 |
|f buffer n nRead|
|
|
41 |
|
|
42 |
f := 'testFile' asFilename readStream binary.
|
|
43 |
buffer := ByteArray new:128.
|
|
44 |
|
|
45 |
n := 0.
|
|
46 |
[f atEnd] whileFalse:[
|
1
|
47 |
nRead := f nextBytes:128 into:buffer.
|
|
48 |
n := n + nRead.
|
0
|
49 |
].
|
|
50 |
f close.
|
|
51 |
expect ~~ n ifTrue:[
|
1
|
52 |
self halt:('got <1p>; expected:<2p>' expandMacrosWith:n with:expect)
|
0
|
53 |
].
|
|
54 |
|
|
55 |
"Created: / 12.8.1998 / 13:29:41 / cg"
|
|
56 |
"Modified: / 12.8.1998 / 13:36:40 / cg"
|
|
57 |
!
|
|
58 |
|
|
59 |
test1
|
|
60 |
"read a file - check count read with files size."
|
|
61 |
|
|
62 |
|sz|
|
|
63 |
|
|
64 |
self createTestFile.
|
|
65 |
|
|
66 |
sz := 'testFile' asFilename fileSize.
|
|
67 |
|
|
68 |
self readFileExpecting:sz.
|
|
69 |
|
|
70 |
"
|
|
71 |
self test1
|
|
72 |
"
|
|
73 |
|
|
74 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
75 |
!
|
|
76 |
|
|
77 |
test2
|
|
78 |
"read a file - check count read with files size.
|
|
79 |
Do this in 20 threads"
|
|
80 |
|
|
81 |
|sz|
|
|
82 |
|
|
83 |
self createTestFile.
|
|
84 |
|
|
85 |
sz := 'testFile' asFilename fileSize.
|
|
86 |
|
|
87 |
20 timesRepeat:[
|
1
|
88 |
[self readFileExpecting:sz. 'done' printCR.] fork.
|
0
|
89 |
].
|
|
90 |
|
|
91 |
"
|
|
92 |
self test2
|
|
93 |
"
|
|
94 |
|
|
95 |
"Modified: / 12.8.1998 / 13:30:55 / cg"
|
|
96 |
!
|
|
97 |
|
|
98 |
test3
|
|
99 |
"read a file - check count read with files size.
|
|
100 |
Do this and interrupt the reading thread heavily"
|
|
101 |
|
|
102 |
|sz p count nLoop|
|
|
103 |
|
|
104 |
nLoop := 1000.
|
|
105 |
|
|
106 |
self createTestFile.
|
|
107 |
|
|
108 |
sz := 'testFile' asFilename fileSize.
|
|
109 |
|
|
110 |
p := [
|
30
|
111 |
nLoop timesRepeat:[
|
|
112 |
self readFileExpecting:sz.
|
|
113 |
].
|
|
114 |
] forkAt:7.
|
|
115 |
|
|
116 |
count := 0.
|
|
117 |
[p isDead] whileFalse:[
|
|
118 |
Delay waitForMilliseconds:5.
|
|
119 |
p interruptWith:[count := count + 1].
|
|
120 |
].
|
|
121 |
('read file <1p> times; interrupted <2p> times'
|
|
122 |
expandMacrosWith:nLoop with:count) printCR
|
|
123 |
|
|
124 |
"
|
|
125 |
self test3
|
|
126 |
"
|
|
127 |
|
|
128 |
"Modified: / 12.8.1998 / 13:42:13 / cg"
|
|
129 |
!
|
|
130 |
|
|
131 |
test4
|
|
132 |
"readCheck a pipe.
|
|
133 |
Do this and interrupt the reading thread heavily"
|
|
134 |
|
|
135 |
|sz s p count nLoop|
|
|
136 |
|
|
137 |
nLoop := 1000.
|
|
138 |
|
|
139 |
self createTestFile.
|
|
140 |
|
|
141 |
s := PipeStream readingFrom:'sleep 5'.
|
|
142 |
|
|
143 |
p := [
|
|
144 |
s readWait.
|
|
145 |
'readWait finished' printCR.
|
|
146 |
] forkAt:7.
|
|
147 |
|
|
148 |
count := 0.
|
|
149 |
[p isDead] whileFalse:[
|
|
150 |
Delay waitForMilliseconds:5.
|
|
151 |
p interruptWith:[count := count + 1].
|
|
152 |
].
|
|
153 |
('readWait interrupted <1p> times'
|
|
154 |
expandMacrosWith:count) printCR.
|
|
155 |
|
|
156 |
s close.
|
|
157 |
|
|
158 |
"
|
|
159 |
self test4
|
|
160 |
"
|
|
161 |
|
|
162 |
"Modified: / 12.8.1998 / 13:42:13 / cg"
|
|
163 |
!
|
|
164 |
|
|
165 |
test5
|
|
166 |
"readCheck a pipe.
|
|
167 |
Do this and interrupt the reading thread heavily"
|
|
168 |
|
|
169 |
|sz s p count nLoop|
|
|
170 |
|
|
171 |
nLoop := 1000.
|
|
172 |
|
|
173 |
self createTestFile.
|
|
174 |
|
|
175 |
s := PipeStream readingFrom:'sleep 5; echo hello'.
|
|
176 |
|
|
177 |
p := [
|
|
178 |
s readWait.
|
|
179 |
'readWait finished' printCR.
|
0
|
180 |
] forkAt:7.
|
|
181 |
|
|
182 |
count := 0.
|
|
183 |
[p isDead] whileFalse:[
|
30
|
184 |
Delay waitForMilliseconds:5.
|
|
185 |
p interruptWith:[count := count + 1].
|
0
|
186 |
].
|
30
|
187 |
('readWait interrupted <1p> times'
|
|
188 |
expandMacrosWith:count) printCR.
|
|
189 |
|
|
190 |
s close.
|
0
|
191 |
|
|
192 |
"
|
30
|
193 |
self test5
|
|
194 |
"
|
|
195 |
|
|
196 |
"Modified: / 12.8.1998 / 13:42:13 / cg"
|
|
197 |
!
|
|
198 |
|
|
199 |
test6
|
|
200 |
"read a pipe.
|
|
201 |
Do this and interrupt the reading thread heavily"
|
|
202 |
|
|
203 |
|sz s p count nLoop|
|
|
204 |
|
|
205 |
nLoop := 1000.
|
|
206 |
|
|
207 |
self createTestFile.
|
|
208 |
|
|
209 |
s := PipeStream readingFrom:'sleep 5'.
|
|
210 |
|
|
211 |
p := [
|
|
212 |
'read: ' print. s nextLine printCR.
|
|
213 |
] forkAt:7.
|
|
214 |
|
|
215 |
count := 0.
|
|
216 |
[p isDead] whileFalse:[
|
|
217 |
Delay waitForMilliseconds:5.
|
|
218 |
p interruptWith:[count := count + 1].
|
|
219 |
].
|
|
220 |
('read interrupted <1p> times'
|
|
221 |
expandMacrosWith:count) printCR.
|
|
222 |
|
|
223 |
s close.
|
|
224 |
|
|
225 |
"
|
|
226 |
self test6
|
|
227 |
"
|
|
228 |
|
|
229 |
"Modified: / 12.8.1998 / 13:42:13 / cg"
|
|
230 |
!
|
|
231 |
|
|
232 |
test7
|
|
233 |
"read a pipe.
|
|
234 |
Do this and interrupt the reading thread heavily"
|
|
235 |
|
|
236 |
|sz s p count nLoop|
|
|
237 |
|
|
238 |
nLoop := 1000.
|
|
239 |
|
|
240 |
self createTestFile.
|
|
241 |
|
|
242 |
s := PipeStream readingFrom:'sleep 5; echo hello'.
|
|
243 |
|
|
244 |
p := [
|
|
245 |
'read: ' print. s nextLine printCR.
|
|
246 |
] forkAt:7.
|
|
247 |
|
|
248 |
count := 0.
|
|
249 |
[p isDead] whileFalse:[
|
|
250 |
Delay waitForMilliseconds:5.
|
|
251 |
p interruptWith:[count := count + 1].
|
|
252 |
].
|
|
253 |
('read interrupted <1p> times'
|
|
254 |
expandMacrosWith:count) printCR.
|
|
255 |
|
|
256 |
s close.
|
|
257 |
|
|
258 |
"
|
|
259 |
self test7
|
0
|
260 |
"
|
|
261 |
|
|
262 |
"Modified: / 12.8.1998 / 13:42:13 / cg"
|
|
263 |
! !
|
|
264 |
|
|
265 |
!FileStreamTest class methodsFor:'documentation'!
|
|
266 |
|
|
267 |
version
|
|
268 |
^ '$Header$'
|
|
269 |
! !
|