2515
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
2507
|
3 |
"{ Package: 'stx:goodies/regression' }"
|
|
4 |
|
|
5 |
"{ NameSpace: RegressionTests }"
|
|
6 |
|
|
7 |
TestCase subclass:#WebSocketTest
|
2527
|
8 |
instanceVariableNames:''
|
|
9 |
classVariableNames:'ServerWebSocket ClientWebSocket'
|
|
10 |
poolDictionaries:''
|
|
11 |
category:'tests-Regression-Web'
|
2507
|
12 |
!
|
|
13 |
|
|
14 |
HTTPService subclass:#DemoWebSocketService
|
2527
|
15 |
instanceVariableNames:'webSocketCreationCallback'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
privateIn:WebSocketTest
|
2507
|
19 |
!
|
|
20 |
|
|
21 |
!WebSocketTest class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
documentation
|
|
24 |
"
|
|
25 |
documentation to be added.
|
|
26 |
|
|
27 |
class:
|
|
28 |
<a short class summary here, describing what instances represent>
|
|
29 |
|
|
30 |
responsibilities:
|
|
31 |
<describing what my main role is>
|
|
32 |
|
|
33 |
collaborators:
|
|
34 |
<describing with whom and how I talk to>
|
|
35 |
|
|
36 |
API:
|
|
37 |
<public api and main messages>
|
|
38 |
|
|
39 |
example:
|
|
40 |
<a one-line examples on how to use - can also be in a separate example method>
|
|
41 |
|
|
42 |
implementation:
|
|
43 |
<implementation points>
|
|
44 |
|
|
45 |
[author:]
|
|
46 |
Stefan Reise
|
|
47 |
|
|
48 |
[instance variables:]
|
|
49 |
|
|
50 |
[class variables:]
|
|
51 |
|
|
52 |
[see also:]
|
|
53 |
|
|
54 |
"
|
|
55 |
! !
|
|
56 |
|
|
57 |
!WebSocketTest class methodsFor:'actions'!
|
|
58 |
|
|
59 |
resetServerAndClientWebsocket
|
|
60 |
"
|
|
61 |
self resetServerAndClientWebsocket
|
|
62 |
"
|
|
63 |
|
|
64 |
ServerWebSocket := nil.
|
|
65 |
ClientWebSocket := nil.
|
|
66 |
|
|
67 |
"Created: / 17-01-2020 / 13:37:18 / Stefan Reise"
|
|
68 |
! !
|
|
69 |
|
|
70 |
!WebSocketTest methodsFor:'data'!
|
|
71 |
|
|
72 |
allData
|
2516
|
73 |
"
|
|
74 |
self new allData
|
|
75 |
"
|
|
76 |
|
2507
|
77 |
|allData|
|
|
78 |
|
|
79 |
allData := OrderedCollection new.
|
|
80 |
self allDataWithFrameHash pairWiseDo:[:first :second |
|
|
81 |
allData add:first.
|
|
82 |
].
|
|
83 |
|
|
84 |
^ allData
|
|
85 |
|
|
86 |
"Created: / 20-01-2020 / 13:56:05 / Stefan Reise"
|
2516
|
87 |
"Modified (comment): / 21-01-2020 / 10:38:54 / Stefan Reise"
|
2507
|
88 |
!
|
|
89 |
|
|
90 |
allDataWithFrameHash
|
2516
|
91 |
"
|
|
92 |
self new allDataWithFrameHash
|
|
93 |
"
|
|
94 |
|
2507
|
95 |
^ self dataWithLength0AndFrameHash "/ zero data
|
|
96 |
, self dataWithLength11AndFrameHash "/ just hello world
|
|
97 |
, self dataWithLength125AndFrameHash "/ last fitting length for the single byte
|
|
98 |
, self dataWithLength126AndFrameHash "/ first length to put into for 2 bytes according to the protocol
|
|
99 |
, self dataWithLength127AndFrameHash "/ first length + 1 to put into 2 bytes
|
|
100 |
, self dataWithLength65535AndFrameHash "/ last fitting length for 2 bytes
|
|
101 |
, self dataWithLength65536AndFrameHash "/ first length to put into 8 bytes according to the protocol
|
|
102 |
, self dataWithLength70536AndFrameHash "/ random length to put into 8 bytes
|
|
103 |
, self dataWithLengthMaxPerFrameAndFrameHash "/ last fitting length for max frame length
|
|
104 |
, self dataWithLengthMaxPerFramePlus1AndFrameHash "/ first length to put into multiple frames
|
|
105 |
, self dataWithLengthMaxTestAndFrameHash "/ max length for testing
|
|
106 |
|
|
107 |
"Created: / 20-01-2020 / 13:54:14 / Stefan Reise"
|
2516
|
108 |
"Modified (comment): / 21-01-2020 / 10:38:30 / Stefan Reise"
|
2507
|
109 |
!
|
|
110 |
|
2524
|
111 |
byteArray100
|
|
112 |
^ ByteArray new:100 * 1024 * 1024
|
|
113 |
|
|
114 |
"Created: / 22-01-2020 / 15:42:28 / Stefan Reise"
|
|
115 |
!
|
|
116 |
|
|
117 |
byteArray500
|
|
118 |
^ ByteArray new:500 * 1024 * 1024
|
|
119 |
|
|
120 |
"Created: / 22-01-2020 / 15:42:32 / Stefan Reise"
|
|
121 |
!
|
|
122 |
|
|
123 |
data100
|
|
124 |
^ String new:100 * 1024 * 1024
|
|
125 |
|
|
126 |
"Created: / 22-01-2020 / 15:40:35 / Stefan Reise"
|
|
127 |
!
|
|
128 |
|
|
129 |
data500
|
|
130 |
^ String new:512 * 1024 * 1024
|
|
131 |
|
|
132 |
"Created: / 22-01-2020 / 15:40:58 / Stefan Reise"
|
|
133 |
!
|
|
134 |
|
2507
|
135 |
dataWithLength0AndFrameHash
|
|
136 |
^ #(
|
|
137 |
''
|
|
138 |
33024
|
|
139 |
)
|
|
140 |
|
|
141 |
"Created: / 20-01-2020 / 13:24:23 / Stefan Reise"
|
|
142 |
!
|
|
143 |
|
|
144 |
dataWithLength11AndFrameHash
|
|
145 |
^ #(
|
|
146 |
'Hello World'
|
|
147 |
457351956
|
|
148 |
)
|
|
149 |
|
|
150 |
"Created: / 20-01-2020 / 13:24:42 / Stefan Reise"
|
|
151 |
!
|
|
152 |
|
|
153 |
dataWithLength125AndFrameHash
|
|
154 |
^ #(
|
|
155 |
'12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345'
|
|
156 |
854990094
|
|
157 |
)
|
|
158 |
|
|
159 |
"Created: / 20-01-2020 / 13:21:12 / Stefan Reise"
|
|
160 |
!
|
|
161 |
|
|
162 |
dataWithLength126AndFrameHash
|
|
163 |
^ #(
|
|
164 |
'123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456'
|
|
165 |
386953194
|
|
166 |
)
|
|
167 |
|
|
168 |
"Created: / 20-01-2020 / 13:21:15 / Stefan Reise"
|
|
169 |
!
|
|
170 |
|
|
171 |
dataWithLength127AndFrameHash
|
|
172 |
^ #(
|
|
173 |
'1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567'
|
|
174 |
1015153950
|
|
175 |
)
|
|
176 |
|
|
177 |
"Created: / 20-01-2020 / 13:21:18 / Stefan Reise"
|
|
178 |
!
|
|
179 |
|
|
180 |
dataWithLength65535AndFrameHash
|
|
181 |
|string|
|
|
182 |
|
|
183 |
string := String new:65535.
|
|
184 |
|
|
185 |
^ Array
|
|
186 |
with:string
|
|
187 |
with:526675651
|
|
188 |
|
|
189 |
"Created: / 20-01-2020 / 13:21:20 / Stefan Reise"
|
|
190 |
!
|
|
191 |
|
|
192 |
dataWithLength65536AndFrameHash
|
|
193 |
|string|
|
|
194 |
|
|
195 |
string := String new:65536.
|
|
196 |
|
|
197 |
^ Array
|
|
198 |
with:string
|
|
199 |
with:894588570
|
|
200 |
|
|
201 |
"Created: / 20-01-2020 / 13:21:23 / Stefan Reise"
|
|
202 |
!
|
|
203 |
|
|
204 |
dataWithLength70536AndFrameHash
|
|
205 |
|string|
|
|
206 |
|
|
207 |
string := String new:70536.
|
|
208 |
|
|
209 |
^ Array
|
|
210 |
with:string
|
|
211 |
with:201475330
|
|
212 |
|
|
213 |
"Created: / 20-01-2020 / 13:21:25 / Stefan Reise"
|
|
214 |
!
|
|
215 |
|
|
216 |
dataWithLengthMaxPerFrameAndFrameHash
|
|
217 |
|string|
|
|
218 |
|
2530
|
219 |
string := String new:WebSocketStream maxBytesPerFrame.
|
2507
|
220 |
|
|
221 |
^ Array
|
|
222 |
with:string
|
|
223 |
with:656112522
|
|
224 |
|
|
225 |
"Created: / 20-01-2020 / 13:59:13 / Stefan Reise"
|
|
226 |
!
|
|
227 |
|
|
228 |
dataWithLengthMaxPerFramePlus1AndFrameHash
|
|
229 |
|string|
|
|
230 |
|
2530
|
231 |
string := String new:WebSocketStream maxBytesPerFrame + 1.
|
2507
|
232 |
|
|
233 |
^ Array
|
|
234 |
with:string
|
|
235 |
with:95386507
|
|
236 |
|
|
237 |
"Created: / 20-01-2020 / 14:03:29 / Stefan Reise"
|
|
238 |
!
|
|
239 |
|
|
240 |
dataWithLengthMaxTestAndFrameHash
|
|
241 |
|string|
|
|
242 |
|
|
243 |
string := String new:5 * 1024 * 1024. "/ 5mb
|
|
244 |
|
|
245 |
^ Array
|
|
246 |
with:string
|
|
247 |
with:888620042
|
|
248 |
|
|
249 |
"Created: / 20-01-2020 / 14:04:40 / Stefan Reise"
|
|
250 |
! !
|
|
251 |
|
|
252 |
!WebSocketTest methodsFor:'helper'!
|
|
253 |
|
2524
|
254 |
communicationWithData:dataArrayOrData
|
|
255 |
doAssert:doAssert
|
|
256 |
|
2528
|
257 |
|nextData|
|
|
258 |
|
2524
|
259 |
^ self
|
|
260 |
withData:dataArrayOrData
|
|
261 |
do:[:eachData |
|
|
262 |
self clientWebSocket nextPut:eachData.
|
2528
|
263 |
nextData := self serverWebSocket next.
|
2524
|
264 |
doAssert ifTrue:[
|
2528
|
265 |
self assert:nextData = eachData.
|
2524
|
266 |
].
|
2507
|
267 |
|
2524
|
268 |
self serverWebSocket nextPut:eachData.
|
2528
|
269 |
nextData := self clientWebSocket next.
|
2524
|
270 |
doAssert ifTrue:[
|
2528
|
271 |
self assert:nextData = eachData.
|
2524
|
272 |
].
|
|
273 |
]
|
|
274 |
|
|
275 |
"Created: / 22-01-2020 / 16:19:34 / Stefan Reise"
|
2528
|
276 |
"Modified: / 23-01-2020 / 11:45:24 / Stefan Reise"
|
2524
|
277 |
!
|
|
278 |
|
|
279 |
maskAndUnmaskData:dataArrayOrData
|
|
280 |
doAssert:doAssert
|
2507
|
281 |
|
2524
|
282 |
|webSocket mask eachDataAsByteArray eachMasked eachUnmasked|
|
|
283 |
|
|
284 |
webSocket := WebSocketStream new.
|
|
285 |
mask := #[12 214 166 43].
|
|
286 |
|
|
287 |
^ self
|
|
288 |
withData:dataArrayOrData
|
|
289 |
do:[:eachByteArrayOrString |
|
|
290 |
eachDataAsByteArray := eachByteArrayOrString asByteArray.
|
2507
|
291 |
|
2524
|
292 |
eachMasked := webSocket
|
|
293 |
maskOrUnmaskPayload:eachDataAsByteArray
|
|
294 |
withMask:mask.
|
|
295 |
|
|
296 |
eachUnmasked := webSocket
|
|
297 |
maskOrUnmaskPayload:eachMasked
|
|
298 |
withMask:mask.
|
|
299 |
|
|
300 |
doAssert ifTrue:[
|
|
301 |
self assert:eachUnmasked = eachDataAsByteArray.
|
|
302 |
].
|
|
303 |
]
|
2507
|
304 |
|
2524
|
305 |
"Created: / 22-01-2020 / 16:22:41 / Stefan Reise"
|
|
306 |
!
|
|
307 |
|
|
308 |
withData:dataArrayOrData
|
|
309 |
do:aBlock
|
|
310 |
|
|
311 |
|startTimestamp dataArray timeDurationUsed|
|
|
312 |
|
|
313 |
startTimestamp := Timestamp now.
|
|
314 |
|
|
315 |
dataArray := dataArrayOrData.
|
|
316 |
(dataArrayOrData firstIfEmpty:nil) isCollection ifFalse:[
|
|
317 |
dataArray := Array with:dataArrayOrData.
|
|
318 |
].
|
|
319 |
|
|
320 |
dataArray do:aBlock.
|
|
321 |
|
|
322 |
timeDurationUsed := Timestamp now - startTimestamp.
|
|
323 |
Transcript showCR:timeDurationUsed printString.
|
|
324 |
|
|
325 |
^ timeDurationUsed
|
2507
|
326 |
|
2524
|
327 |
"Created: / 22-01-2020 / 16:21:30 / Stefan Reise"
|
|
328 |
! !
|
|
329 |
|
|
330 |
!WebSocketTest methodsFor:'queries'!
|
|
331 |
|
|
332 |
clientWebSocket
|
|
333 |
ClientWebSocket isNil ifTrue:[
|
|
334 |
self setupServerAndClientWebsocket.
|
|
335 |
].
|
|
336 |
|
|
337 |
^ ClientWebSocket
|
2507
|
338 |
|
2524
|
339 |
"Created: / 17-01-2020 / 13:23:11 / Stefan Reise"
|
2507
|
340 |
!
|
|
341 |
|
2524
|
342 |
serverWebSocket
|
|
343 |
ServerWebSocket isNil ifTrue:[
|
|
344 |
self setupServerAndClientWebsocket.
|
|
345 |
].
|
|
346 |
|
|
347 |
^ ServerWebSocket
|
|
348 |
|
|
349 |
"Created: / 17-01-2020 / 13:23:15 / Stefan Reise"
|
|
350 |
! !
|
|
351 |
|
|
352 |
!WebSocketTest methodsFor:'setup'!
|
|
353 |
|
2507
|
354 |
setupServerAndClientWebsocket
|
|
355 |
"
|
|
356 |
self resetServerAndClientWebsocket
|
|
357 |
"
|
|
358 |
|
|
359 |
|response|
|
|
360 |
|
|
361 |
DemoWebSocketService start
|
|
362 |
webSocketCreationCallback:[:newWebSocket |
|
|
363 |
ServerWebSocket := newWebSocket.
|
|
364 |
].
|
|
365 |
|
|
366 |
response := HTTPInterface
|
|
367 |
get:('ws://localhost:%1%2'
|
|
368 |
bindWith:DemoWebSocketService defaultPort
|
|
369 |
with:DemoWebSocketService linkName).
|
|
370 |
|
|
371 |
response isErrorResponse ifTrue:[
|
|
372 |
self error:'failed to connect'.
|
|
373 |
].
|
|
374 |
|
|
375 |
ClientWebSocket := response webSocket.
|
|
376 |
|
|
377 |
"Created: / 17-01-2020 / 13:21:28 / Stefan Reise"
|
2515
|
378 |
"Modified: / 20-01-2020 / 18:08:26 / Stefan Reise"
|
2507
|
379 |
! !
|
|
380 |
|
|
381 |
!WebSocketTest methodsFor:'tests'!
|
|
382 |
|
|
383 |
testCommunication
|
|
384 |
"
|
2524
|
385 |
!! call the following method in case the sockets did get corrupted !!
|
|
386 |
self resetServerAndClientWebsocket
|
|
387 |
|
|
388 |
WebSocketStream verbose:true.
|
|
389 |
WebSocketStream verboseProtocol:true.
|
|
390 |
|
|
391 |
WebSocketStream verbose:false.
|
|
392 |
WebSocketStream verboseProtocol:false.
|
|
393 |
|
2530
|
394 |
WebSocketStream maxBytesPerFrame:1024.
|
|
395 |
WebSocketStream maxBytesPerFrame:nil.
|
2524
|
396 |
"
|
|
397 |
|
|
398 |
self
|
|
399 |
communicationWithData:self allData
|
|
400 |
doAssert:true.
|
|
401 |
|
|
402 |
"Created: / 17-01-2020 / 13:24:24 / Stefan Reise"
|
|
403 |
"Modified: / 22-01-2020 / 16:25:01 / Stefan Reise"
|
2530
|
404 |
"Modified (comment): / 23-01-2020 / 11:59:45 / Stefan Reise"
|
2524
|
405 |
!
|
|
406 |
|
|
407 |
testCommunication100
|
|
408 |
"
|
|
409 |
!! call the following method in case the sockets did get corrupted !!
|
2515
|
410 |
self resetServerAndClientWebsocket
|
|
411 |
|
|
412 |
WebSocketStream verbose:true.
|
|
413 |
WebSocketStream verboseProtocol:true.
|
|
414 |
|
|
415 |
WebSocketStream verbose:false.
|
|
416 |
WebSocketStream verboseProtocol:false.
|
|
417 |
|
2530
|
418 |
WebSocketStream maxBytesPerFrame:1024.
|
|
419 |
WebSocketStream maxBytesPerFrame:nil.
|
2507
|
420 |
"
|
|
421 |
|
2524
|
422 |
self
|
|
423 |
communicationWithData:self data100
|
|
424 |
doAssert:true.
|
|
425 |
|
|
426 |
"Created: / 22-01-2020 / 16:39:15 / Stefan Reise"
|
2530
|
427 |
"Modified (comment): / 23-01-2020 / 11:59:47 / Stefan Reise"
|
2524
|
428 |
!
|
|
429 |
|
|
430 |
testCommunication500
|
|
431 |
"
|
|
432 |
!! call the following method in case the sockets did get corrupted !!
|
|
433 |
self resetServerAndClientWebsocket
|
|
434 |
|
|
435 |
WebSocketStream verbose:true.
|
|
436 |
WebSocketStream verboseProtocol:true.
|
|
437 |
|
|
438 |
WebSocketStream verbose:false.
|
|
439 |
WebSocketStream verboseProtocol:false.
|
|
440 |
|
2530
|
441 |
WebSocketStream maxBytesPerFrame:1024.
|
|
442 |
WebSocketStream maxBytesPerFrame:nil.
|
2524
|
443 |
"
|
|
444 |
|
|
445 |
self
|
|
446 |
communicationWithData:self data500
|
|
447 |
doAssert:true.
|
2507
|
448 |
|
2524
|
449 |
"Created: / 22-01-2020 / 16:39:19 / Stefan Reise"
|
2530
|
450 |
"Modified (comment): / 23-01-2020 / 11:59:52 / Stefan Reise"
|
2524
|
451 |
!
|
|
452 |
|
2526
|
453 |
testCommunicationByteArray500
|
2525
|
454 |
"
|
|
455 |
!! call the following method in case the sockets did get corrupted !!
|
|
456 |
self resetServerAndClientWebsocket
|
|
457 |
|
|
458 |
WebSocketStream verbose:true.
|
|
459 |
WebSocketStream verboseProtocol:true.
|
|
460 |
|
|
461 |
WebSocketStream verbose:false.
|
|
462 |
WebSocketStream verboseProtocol:false.
|
|
463 |
|
2530
|
464 |
WebSocketStream maxBytesPerFrame:1024.
|
|
465 |
WebSocketStream maxBytesPerFrame:nil.
|
2525
|
466 |
"
|
|
467 |
|
|
468 |
self
|
|
469 |
communicationWithData:self byteArray500
|
|
470 |
doAssert:true.
|
|
471 |
|
2526
|
472 |
"Created: / 22-01-2020 / 17:45:53 / Stefan Reise"
|
2530
|
473 |
"Modified (comment): / 23-01-2020 / 11:59:55 / Stefan Reise"
|
2525
|
474 |
!
|
|
475 |
|
2524
|
476 |
testCommunicationSmallFrameSize
|
|
477 |
"
|
|
478 |
!! call the following method in case the sockets did get corrupted !!
|
|
479 |
self resetServerAndClientWebsocket
|
|
480 |
|
|
481 |
WebSocketStream verbose:true.
|
|
482 |
WebSocketStream verboseProtocol:true.
|
|
483 |
|
|
484 |
WebSocketStream verbose:false.
|
|
485 |
WebSocketStream verboseProtocol:false.
|
2507
|
486 |
|
2530
|
487 |
WebSocketStream maxBytesPerFrame:1024.
|
|
488 |
WebSocketStream maxBytesPerFrame:nil.
|
2524
|
489 |
"
|
|
490 |
|
|
491 |
|maxSizeInByterPerFrameBefore|
|
|
492 |
|
2530
|
493 |
maxSizeInByterPerFrameBefore := WebSocketStream maxBytesPerFrame.
|
|
494 |
WebSocketStream maxBytesPerFrame:1024.
|
2524
|
495 |
|
|
496 |
self
|
|
497 |
communicationWithData:self allData
|
|
498 |
doAssert:true.
|
|
499 |
|
2530
|
500 |
WebSocketStream maxBytesPerFrame:maxSizeInByterPerFrameBefore.
|
2524
|
501 |
|
|
502 |
"Created: / 22-01-2020 / 16:17:28 / Stefan Reise"
|
2530
|
503 |
"Modified (comment): / 23-01-2020 / 11:59:57 / Stefan Reise"
|
2516
|
504 |
!
|
|
505 |
|
|
506 |
testCommunicationWithDelay
|
|
507 |
"
|
2524
|
508 |
!! call the following method in case the sockets did get corrupted !!
|
2516
|
509 |
self resetServerAndClientWebsocket
|
|
510 |
|
|
511 |
WebSocketStream verbose:true.
|
|
512 |
WebSocketStream verboseProtocol:true.
|
|
513 |
|
|
514 |
WebSocketStream verbose:false.
|
|
515 |
WebSocketStream verboseProtocol:false.
|
|
516 |
|
2530
|
517 |
WebSocketStream maxBytesPerFrame:1024.
|
|
518 |
WebSocketStream maxBytesPerFrame:nil.
|
2516
|
519 |
"
|
|
520 |
|
|
521 |
self allData do:[:data |
|
|
522 |
self clientWebSocket nextPut:data.
|
|
523 |
].
|
|
524 |
|
|
525 |
Delay waitForSeconds:2.
|
|
526 |
|
|
527 |
self allData do:[:data |
|
|
528 |
self assert:self serverWebSocket next = data.
|
|
529 |
self serverWebSocket nextPut:data.
|
|
530 |
].
|
|
531 |
|
|
532 |
Delay waitForSeconds:2.
|
|
533 |
|
|
534 |
self allData do:[:data |
|
|
535 |
self assert:self clientWebSocket next = data.
|
|
536 |
].
|
|
537 |
|
|
538 |
"Created: / 21-01-2020 / 11:26:23 / Stefan Reise"
|
2530
|
539 |
"Modified (comment): / 23-01-2020 / 12:00:00 / Stefan Reise"
|
2507
|
540 |
!
|
|
541 |
|
|
542 |
testEncoding
|
|
543 |
"
|
2524
|
544 |
!! call the following method in case the sockets did get corrupted !!
|
2515
|
545 |
self resetServerAndClientWebsocket
|
|
546 |
|
|
547 |
WebSocketStream verbose:true.
|
|
548 |
WebSocketStream verboseProtocol:true.
|
|
549 |
|
|
550 |
WebSocketStream verbose:false.
|
|
551 |
WebSocketStream verboseProtocol:false.
|
2507
|
552 |
"
|
|
553 |
|
2524
|
554 |
|serverWebSocket clientWebSocket
|
|
555 |
decodeBlock
|
2530
|
556 |
maxBytesPerFrameBefore|
|
2524
|
557 |
|
|
558 |
serverWebSocket := self serverWebSocket.
|
|
559 |
clientWebSocket := self clientWebSocket.
|
|
560 |
|
|
561 |
decodeBlock :=
|
|
562 |
[:eachWebSocket :eachFrame |
|
|
563 |
((eachWebSocket decodeFrameHybi17:eachFrame) payload ? '') asString
|
|
564 |
].
|
|
565 |
|
|
566 |
[
|
|
567 |
"inside #allDataWithFrameHash is #dataWithLengthMaxPerFrameAndFrameHash,
|
2530
|
568 |
which hash do depent on the #maxBytesPerFrame,
|
2524
|
569 |
so set the value, which was used when the hast has been recored"
|
2530
|
570 |
maxBytesPerFrameBefore := WebSocketStream maxBytesPerFrame.
|
|
571 |
WebSocketStream maxBytesPerFrame:512 * 1024.
|
2524
|
572 |
|
|
573 |
self allDataWithFrameHash
|
|
574 |
pairWiseDo:[:eachData :eachExpectedHashForServer |
|
|
575 |
|eachFrame|
|
|
576 |
|
|
577 |
"server -> client"
|
|
578 |
eachFrame := serverWebSocket encodeFrameHybi17Text:eachData.
|
|
579 |
self assert:eachFrame hash = eachExpectedHashForServer.
|
|
580 |
self assert:eachData = (decodeBlock value:clientWebSocket value:eachFrame).
|
|
581 |
|
|
582 |
"client -> server"
|
|
583 |
eachFrame := clientWebSocket encodeFrameHybi17Text:eachData.
|
|
584 |
"/ not able to check against hash from client requests, because they are masked randomly
|
|
585 |
self assert:eachData = (decodeBlock value:serverWebSocket value:eachFrame).
|
|
586 |
].
|
|
587 |
] ensure:[
|
2530
|
588 |
maxBytesPerFrameBefore notNil ifTrue:[
|
|
589 |
WebSocketStream maxBytesPerFrame:maxBytesPerFrameBefore.
|
2524
|
590 |
].
|
|
591 |
].
|
2507
|
592 |
|
|
593 |
"Created: / 20-01-2020 / 13:13:50 / Stefan Reise"
|
2530
|
594 |
"Modified (format): / 23-01-2020 / 12:00:07 / Stefan Reise"
|
2507
|
595 |
!
|
|
596 |
|
|
597 |
testMask
|
2524
|
598 |
self
|
|
599 |
maskAndUnmaskData:self allData
|
|
600 |
doAssert:true.
|
2507
|
601 |
|
|
602 |
"Created: / 20-01-2020 / 15:08:27 / Stefan Reise"
|
2524
|
603 |
"Modified: / 22-01-2020 / 16:22:48 / Stefan Reise"
|
|
604 |
!
|
|
605 |
|
|
606 |
testMask100
|
|
607 |
self
|
|
608 |
maskAndUnmaskData:self byteArray100
|
|
609 |
doAssert:true.
|
|
610 |
|
|
611 |
"Created: / 22-01-2020 / 15:41:29 / Stefan Reise"
|
|
612 |
!
|
|
613 |
|
|
614 |
testMask500
|
|
615 |
self
|
|
616 |
maskAndUnmaskData:self byteArray500
|
|
617 |
doAssert:true.
|
|
618 |
|
|
619 |
"Created: / 22-01-2020 / 15:41:35 / Stefan Reise"
|
2507
|
620 |
!
|
|
621 |
|
2529
|
622 |
testParallelSocketWrite
|
|
623 |
"
|
|
624 |
!! call the following method in case the sockets did get corrupted !!
|
|
625 |
self resetServerAndClientWebsocket
|
|
626 |
|
|
627 |
WebSocketStream verbose:true.
|
|
628 |
WebSocketStream verboseProtocol:true.
|
|
629 |
|
|
630 |
WebSocketStream verbose:false.
|
|
631 |
WebSocketStream verboseProtocol:false.
|
|
632 |
"
|
|
633 |
|
|
634 |
^ self
|
|
635 |
withData:self data100
|
|
636 |
do:[:eachData |
|
|
637 |
self clientWebSocket nextPut:eachData.
|
|
638 |
self serverWebSocket nextPut:eachData.
|
|
639 |
]
|
|
640 |
|
|
641 |
"Created: / 23-01-2020 / 11:47:47 / Stefan Reise"
|
|
642 |
!
|
|
643 |
|
2507
|
644 |
testPing
|
|
645 |
"
|
2524
|
646 |
!! call the following method in case the sockets did get corrupted !!
|
|
647 |
self resetServerAndClientWebsocket
|
2515
|
648 |
|
|
649 |
WebSocketStream verbose:true.
|
|
650 |
WebSocketStream verboseProtocol:true.
|
|
651 |
|
|
652 |
WebSocketStream verbose:false.
|
|
653 |
WebSocketStream verboseProtocol:false.
|
2507
|
654 |
"
|
|
655 |
|
|
656 |
|pingTimeDuration|
|
|
657 |
|
|
658 |
pingTimeDuration := self clientWebSocket ping.
|
|
659 |
Transcript showCR:pingTimeDuration printString.
|
|
660 |
self assert:pingTimeDuration notNil.
|
|
661 |
|
|
662 |
pingTimeDuration := self serverWebSocket ping.
|
|
663 |
Transcript showCR:pingTimeDuration printString.
|
|
664 |
self assert:pingTimeDuration notNil.
|
|
665 |
|
|
666 |
"Created: / 17-01-2020 / 13:43:58 / Stefan Reise"
|
2524
|
667 |
"Modified (comment): / 22-01-2020 / 15:25:11 / Stefan Reise"
|
|
668 |
! !
|
|
669 |
|
|
670 |
!WebSocketTest methodsFor:'tests speed'!
|
|
671 |
|
2527
|
672 |
testCommunication100Speed
|
|
673 |
"
|
|
674 |
!! call the following method in case the sockets did get corrupted !!
|
|
675 |
self resetServerAndClientWebsocket
|
|
676 |
|
|
677 |
WebSocketStream verbose:true.
|
|
678 |
WebSocketStream verboseProtocol:true.
|
|
679 |
|
|
680 |
WebSocketStream verbose:false.
|
|
681 |
WebSocketStream verboseProtocol:false.
|
|
682 |
|
2530
|
683 |
WebSocketStream maxBytesPerFrame:1024.
|
|
684 |
WebSocketStream maxBytesPerFrame:nil.
|
2527
|
685 |
"
|
|
686 |
|
|
687 |
self
|
|
688 |
communicationWithData:self data100
|
|
689 |
doAssert:false.
|
|
690 |
|
|
691 |
"Created: / 23-01-2020 / 11:32:34 / Stefan Reise"
|
|
692 |
!
|
|
693 |
|
2524
|
694 |
testMask100Speed
|
|
695 |
self
|
|
696 |
assert:(self
|
|
697 |
maskAndUnmaskData:self byteArray100
|
|
698 |
doAssert:false)
|
|
699 |
< 10 seconds.
|
|
700 |
|
|
701 |
"Created: / 22-01-2020 / 15:49:01 / Stefan Reise"
|
|
702 |
!
|
|
703 |
|
|
704 |
testMask500Speed
|
|
705 |
self
|
|
706 |
assert:(self
|
|
707 |
maskAndUnmaskData:self byteArray500
|
|
708 |
doAssert:false)
|
|
709 |
< 50 seconds.
|
|
710 |
|
|
711 |
"Created: / 22-01-2020 / 15:48:52 / Stefan Reise"
|
2507
|
712 |
! !
|
|
713 |
|
|
714 |
!WebSocketTest methodsFor:'zzz'!
|
|
715 |
|
|
716 |
testOnEchoServer
|
2523
|
717 |
"/ |rply|
|
|
718 |
"/
|
|
719 |
"/ rply := HTTPInterface get:'ws://echo.websocket.org'.
|
|
720 |
"/ rply isErrorResponse ifTrue:[
|
|
721 |
"/ self error:'failed to connect'.
|
|
722 |
"/ ].
|
|
723 |
"/
|
|
724 |
"/ rply webSocket
|
2507
|
725 |
|
|
726 |
"Created: / 15-01-2020 / 15:55:27 / Stefan Reise"
|
2523
|
727 |
"Modified: / 21-01-2020 / 16:11:15 / Stefan Reise"
|
2507
|
728 |
! !
|
|
729 |
|
|
730 |
!WebSocketTest::DemoWebSocketService class methodsFor:'constants'!
|
|
731 |
|
|
732 |
defaultPort
|
|
733 |
^ 9095
|
|
734 |
|
|
735 |
"Created: / 18-11-2019 / 13:19:29 / Stefan Reise"
|
|
736 |
!
|
|
737 |
|
|
738 |
linkName
|
|
739 |
^ '/websocket'
|
|
740 |
|
|
741 |
"Created: / 13-11-2019 / 13:30:11 / Stefan Reise"
|
|
742 |
! !
|
|
743 |
|
|
744 |
!WebSocketTest::DemoWebSocketService class methodsFor:'documentation'!
|
|
745 |
|
|
746 |
documentation
|
|
747 |
"
|
|
748 |
[start Server with:]
|
|
749 |
HTTPServer startServerOnPort:8080
|
|
750 |
|
|
751 |
[start with:]
|
|
752 |
(self new)
|
|
753 |
registerServiceOn:(HTTPServer runningServerOnPort:8080)
|
|
754 |
|
|
755 |
class:
|
|
756 |
<a short class summary here, describing what instances represent>
|
|
757 |
|
|
758 |
responsibilities:
|
|
759 |
<describing what my main role is>
|
|
760 |
|
|
761 |
collaborators:
|
|
762 |
<describing with whom and how I talk to>
|
|
763 |
|
|
764 |
API:
|
|
765 |
<public api and main messages>
|
|
766 |
|
|
767 |
example:
|
|
768 |
<a one-line examples on how to use - can also be in a separate example method>
|
|
769 |
|
|
770 |
implementation:
|
|
771 |
<implementation points>
|
|
772 |
|
|
773 |
[author:]
|
|
774 |
Stefan Reise
|
|
775 |
|
|
776 |
[instance variables:]
|
|
777 |
|
|
778 |
[class variables:]
|
|
779 |
|
|
780 |
[see also:]
|
|
781 |
|
|
782 |
"
|
|
783 |
! !
|
|
784 |
|
|
785 |
!WebSocketTest::DemoWebSocketService class methodsFor:'examples'!
|
|
786 |
|
|
787 |
start
|
|
788 |
"
|
|
789 |
self start
|
|
790 |
"
|
|
791 |
|
|
792 |
|httpServer instance|
|
|
793 |
|
|
794 |
httpServer := HTTPServer serverOnPort:self defaultPort.
|
|
795 |
instance := self registerServiceOn:httpServer.
|
|
796 |
httpServer start.
|
|
797 |
|
|
798 |
^ instance
|
|
799 |
|
|
800 |
"Created: / 17-01-2020 / 13:19:08 / Stefan Reise"
|
|
801 |
! !
|
|
802 |
|
|
803 |
!WebSocketTest::DemoWebSocketService methodsFor:'accessing'!
|
|
804 |
|
|
805 |
webSocketCreationCallback:something
|
|
806 |
webSocketCreationCallback := something.
|
|
807 |
! !
|
|
808 |
|
|
809 |
!WebSocketTest::DemoWebSocketService methodsFor:'processing'!
|
|
810 |
|
|
811 |
acceptsWebSocket:webSocket
|
|
812 |
^ true
|
|
813 |
|
|
814 |
"Created: / 13-11-2019 / 13:57:03 / Stefan Reise"
|
|
815 |
!
|
|
816 |
|
|
817 |
startServingWebSocket:webSocket
|
|
818 |
"to be redefined in subclasses (services) which do handle webSockets;
|
|
819 |
close here, in case it was not redefined"
|
|
820 |
|
|
821 |
webSocketCreationCallback value:webSocket.
|
|
822 |
|
|
823 |
"Created: / 13-11-2019 / 14:42:43 / Stefan Reise"
|
|
824 |
"Modified: / 17-01-2020 / 13:19:52 / Stefan Reise"
|
|
825 |
! !
|
|
826 |
|
|
827 |
!WebSocketTest::DemoWebSocketService methodsFor:'queries'!
|
|
828 |
|
|
829 |
allowWebSockets
|
|
830 |
^ true
|
|
831 |
|
|
832 |
"Created: / 13-11-2019 / 13:29:48 / Stefan Reise"
|
|
833 |
! !
|
|
834 |
|
|
835 |
!WebSocketTest class methodsFor:'documentation'!
|
|
836 |
|
|
837 |
version_CVS
|
|
838 |
^ '$Header$'
|
|
839 |
! !
|
|
840 |
|