#FEATURE by Stefan Reise
class: RegressionTests::WebSocketTest
removed:
#assertCommunication
#assertEncodingPairwiseDataAndHash:
#assertMaskForDataArray:
#maskAndUnmaskForData:doAssert:
#maskAndUnmaskForDataArray:doAssert:
#speedTestMask100
#speedTestMask500
#testCommunicationHughData
#testMaskDiff
#testMaskWithHughData
category of:
#setupServerAndClientWebsocket
#testCommunicationWithDelay
#testEncoding
#testMask100Speed
#testMask500Speed
#withData:do:
class: WebSocketTest
added:23 methods
comment/format in:
#assertEncodingPairwiseDataAndHash:
#testCommunication
#testCommunicationWithDelay
#testPing
changed:
#testEncoding (send #payloadData instead of #payload)
#testMask
--- a/RegressionTests__WebSocketTest.st Wed Jan 22 10:51:01 2020 +0100
+++ b/RegressionTests__WebSocketTest.st Wed Jan 22 16:39:41 2020 +0100
@@ -108,6 +108,30 @@
"Modified (comment): / 21-01-2020 / 10:38:30 / Stefan Reise"
!
+byteArray100
+ ^ ByteArray new:100 * 1024 * 1024
+
+ "Created: / 22-01-2020 / 15:42:28 / Stefan Reise"
+!
+
+byteArray500
+ ^ ByteArray new:500 * 1024 * 1024
+
+ "Created: / 22-01-2020 / 15:42:32 / Stefan Reise"
+!
+
+data100
+ ^ String new:100 * 1024 * 1024
+
+ "Created: / 22-01-2020 / 15:40:35 / Stefan Reise"
+!
+
+data500
+ ^ String new:512 * 1024 * 1024
+
+ "Created: / 22-01-2020 / 15:40:58 / Stefan Reise"
+!
+
dataWithLength0AndFrameHash
^ #(
''
@@ -227,38 +251,101 @@
!WebSocketTest methodsFor:'helper'!
-assertEncodingPairwiseDataAndHash:dataAndHash
- "encodes and decode the data for client -> server and server -> client protocol"
+communicationWithData:dataArrayOrData
+ doAssert:doAssert
+
+ ^ self
+ withData:dataArrayOrData
+ do:[:eachData |
+ self clientWebSocket nextPut:eachData.
+ doAssert ifTrue:[
+ self assert:self serverWebSocket next = eachData.
+ ].
- |serverWebSocket clientWebSocket
- decodeBlock
- eachFrame|
+ self serverWebSocket nextPut:eachData.
+ doAssert ifTrue:[
+ self assert:self clientWebSocket next = eachData.
+ ].
+ ]
+
+ "Created: / 22-01-2020 / 16:19:34 / Stefan Reise"
+!
+
+maskAndUnmaskData:dataArrayOrData
+ doAssert:doAssert
- serverWebSocket := self serverWebSocket.
- clientWebSocket := self clientWebSocket.
+ |webSocket mask eachDataAsByteArray eachMasked eachUnmasked|
+
+ webSocket := WebSocketStream new.
+ mask := #[12 214 166 43].
+
+ ^ self
+ withData:dataArrayOrData
+ do:[:eachByteArrayOrString |
+ eachDataAsByteArray := eachByteArrayOrString asByteArray.
- decodeBlock :=
- [:eachWebSocket :eachFrame |
- ((eachWebSocket decodeFrameHybi17:eachFrame) payloadData ? '') asString
- ].
+ eachMasked := webSocket
+ maskOrUnmaskPayload:eachDataAsByteArray
+ withMask:mask.
+
+ eachUnmasked := webSocket
+ maskOrUnmaskPayload:eachMasked
+ withMask:mask.
+
+ doAssert ifTrue:[
+ self assert:eachUnmasked = eachDataAsByteArray.
+ ].
+ ]
- dataAndHash
- pairWiseDo:[:eachData :eachExpectedHashForServer |
- "server -> client"
- eachFrame := serverWebSocket encodeFrameHybi17:eachData.
- self assert:eachFrame hash = eachExpectedHashForServer.
- self assert:eachData = (decodeBlock value:clientWebSocket value:eachFrame).
+ "Created: / 22-01-2020 / 16:22:41 / Stefan Reise"
+!
+
+withData:dataArrayOrData
+ do:aBlock
+
+ |startTimestamp dataArray timeDurationUsed|
+
+ startTimestamp := Timestamp now.
+
+ dataArray := dataArrayOrData.
+ (dataArrayOrData firstIfEmpty:nil) isCollection ifFalse:[
+ dataArray := Array with:dataArrayOrData.
+ ].
+
+ dataArray do:aBlock.
+
+ timeDurationUsed := Timestamp now - startTimestamp.
+ Transcript showCR:timeDurationUsed printString.
+
+ ^ timeDurationUsed
- "client -> server"
- eachFrame := clientWebSocket encodeFrameHybi17:eachData.
- "/ not able to check against hash from client requests, because they are masked randomly
- self assert:eachData = (decodeBlock value:serverWebSocket value:eachFrame).
- ].
+ "Created: / 22-01-2020 / 16:21:30 / Stefan Reise"
+! !
+
+!WebSocketTest methodsFor:'queries'!
+
+clientWebSocket
+ ClientWebSocket isNil ifTrue:[
+ self setupServerAndClientWebsocket.
+ ].
+
+ ^ ClientWebSocket
- "Created: / 17-01-2020 / 17:03:21 / Stefan Reise"
- "Modified (comment): / 20-01-2020 / 13:04:20 / Stefan Reise"
+ "Created: / 17-01-2020 / 13:23:11 / Stefan Reise"
!
+serverWebSocket
+ ServerWebSocket isNil ifTrue:[
+ self setupServerAndClientWebsocket.
+ ].
+
+ ^ ServerWebSocket
+
+ "Created: / 17-01-2020 / 13:23:15 / Stefan Reise"
+! !
+
+!WebSocketTest methodsFor:'setup'!
+
setupServerAndClientWebsocket
"
self resetServerAndClientWebsocket
@@ -286,33 +373,34 @@
"Modified: / 20-01-2020 / 18:08:26 / Stefan Reise"
! !
-!WebSocketTest methodsFor:'queries'!
-
-clientWebSocket
- ClientWebSocket isNil ifTrue:[
- self setupServerAndClientWebsocket.
- ].
-
- ^ ClientWebSocket
-
- "Created: / 17-01-2020 / 13:23:11 / Stefan Reise"
-!
-
-serverWebSocket
- ServerWebSocket isNil ifTrue:[
- self setupServerAndClientWebsocket.
- ].
-
- ^ ServerWebSocket
-
- "Created: / 17-01-2020 / 13:23:15 / Stefan Reise"
-! !
-
!WebSocketTest methodsFor:'tests'!
testCommunication
"
- call the following method in case the sockets did get corrupted
+ !! call the following method in case the sockets did get corrupted !!
+ self resetServerAndClientWebsocket
+
+ WebSocketStream verbose:true.
+ WebSocketStream verboseProtocol:true.
+
+ WebSocketStream verbose:false.
+ WebSocketStream verboseProtocol:false.
+
+ WebSocketStream maxSizeInByterPerFrame:1024.
+ WebSocketStream maxSizeInByterPerFrame:nil.
+ "
+
+ self
+ communicationWithData:self allData
+ doAssert:true.
+
+ "Created: / 17-01-2020 / 13:24:24 / Stefan Reise"
+ "Modified: / 22-01-2020 / 16:25:01 / Stefan Reise"
+!
+
+testCommunication100
+ "
+ !! call the following method in case the sockets did get corrupted !!
self resetServerAndClientWebsocket
WebSocketStream verbose:true.
@@ -325,21 +413,67 @@
WebSocketStream maxSizeInByterPerFrame:nil.
"
- self allData do:[:data |
- self clientWebSocket nextPut:data.
- self assert:self serverWebSocket next = data.
+ self
+ communicationWithData:self data100
+ doAssert:true.
+
+ "Created: / 22-01-2020 / 16:39:15 / Stefan Reise"
+!
+
+testCommunication500
+ "
+ !! call the following method in case the sockets did get corrupted !!
+ self resetServerAndClientWebsocket
+
+ WebSocketStream verbose:true.
+ WebSocketStream verboseProtocol:true.
+
+ WebSocketStream verbose:false.
+ WebSocketStream verboseProtocol:false.
+
+ WebSocketStream maxSizeInByterPerFrame:1024.
+ WebSocketStream maxSizeInByterPerFrame:nil.
+ "
+
+ self
+ communicationWithData:self data500
+ doAssert:true.
- self serverWebSocket nextPut:data.
- self assert:self clientWebSocket next = data.
- ].
+ "Created: / 22-01-2020 / 16:39:19 / Stefan Reise"
+!
+
+testCommunicationSmallFrameSize
+ "
+ !! call the following method in case the sockets did get corrupted !!
+ self resetServerAndClientWebsocket
+
+ WebSocketStream verbose:true.
+ WebSocketStream verboseProtocol:true.
+
+ WebSocketStream verbose:false.
+ WebSocketStream verboseProtocol:false.
- "Created: / 17-01-2020 / 13:24:24 / Stefan Reise"
- "Modified: / 21-01-2020 / 11:25:32 / Stefan Reise"
+ WebSocketStream maxSizeInByterPerFrame:1024.
+ WebSocketStream maxSizeInByterPerFrame:nil.
+ "
+
+ |maxSizeInByterPerFrameBefore|
+
+ maxSizeInByterPerFrameBefore := WebSocketStream maxSizeInByterPerFrame.
+ WebSocketStream maxSizeInByterPerFrame:1024.
+
+ self
+ communicationWithData:self allData
+ doAssert:true.
+
+ WebSocketStream maxSizeInByterPerFrame:maxSizeInByterPerFrameBefore.
+
+ "Created: / 22-01-2020 / 16:17:28 / Stefan Reise"
!
testCommunicationWithDelay
"
- call the following method in case the sockets did get corrupted
+ !! call the following method in case the sockets did get corrupted !!
self resetServerAndClientWebsocket
WebSocketStream verbose:true.
@@ -370,11 +504,12 @@
].
"Created: / 21-01-2020 / 11:26:23 / Stefan Reise"
+ "Modified (comment): / 22-01-2020 / 16:37:22 / Stefan Reise"
!
testEncoding
"
- call the following method in case the sockets did get corrupted
+ !! call the following method in case the sockets did get corrupted !!
self resetServerAndClientWebsocket
WebSocketStream verbose:true.
@@ -384,55 +519,78 @@
WebSocketStream verboseProtocol:false.
"
- "set the value, which was used to record the frame hashe"
- WebSocketStream maxSizeInByterPerFrame:512 * 1024.
- self assertEncodingPairwiseDataAndHash:self allDataWithFrameHash.
- WebSocketStream maxSizeInByterPerFrame:nil.
+ |serverWebSocket clientWebSocket
+ decodeBlock
+ maxSizeInByterPerFrameBefore|
+
+ serverWebSocket := self serverWebSocket.
+ clientWebSocket := self clientWebSocket.
+
+ decodeBlock :=
+ [:eachWebSocket :eachFrame |
+ ((eachWebSocket decodeFrameHybi17:eachFrame) payload ? '') asString
+ ].
+
+ [
+ "inside #allDataWithFrameHash is #dataWithLengthMaxPerFrameAndFrameHash,
+ which hash do depent on the #maxSizeInByterPerFrame,
+ so set the value, which was used when the hast has been recored"
+ maxSizeInByterPerFrameBefore := WebSocketStream maxSizeInByterPerFrame.
+ WebSocketStream maxSizeInByterPerFrame:512 * 1024.
+
+ self allDataWithFrameHash
+ pairWiseDo:[:eachData :eachExpectedHashForServer |
+ |eachFrame|
+
+ "server -> client"
+ eachFrame := serverWebSocket encodeFrameHybi17Text:eachData.
+ self assert:eachFrame hash = eachExpectedHashForServer.
+ self assert:eachData = (decodeBlock value:clientWebSocket value:eachFrame).
+
+ "client -> server"
+ eachFrame := clientWebSocket encodeFrameHybi17Text:eachData.
+ "/ not able to check against hash from client requests, because they are masked randomly
+ self assert:eachData = (decodeBlock value:serverWebSocket value:eachFrame).
+ ].
+ ] ensure:[
+ maxSizeInByterPerFrameBefore notNil ifTrue:[
+ WebSocketStream maxSizeInByterPerFrame:maxSizeInByterPerFrameBefore.
+ ].
+ ].
"Created: / 20-01-2020 / 13:13:50 / Stefan Reise"
- "Modified (comment): / 20-01-2020 / 18:09:08 / Stefan Reise"
+ "Modified (comment): / 22-01-2020 / 16:36:26 / Stefan Reise"
!
testMask
- "
- call the following method in case the sockets did get corrupted
- self resetServerAndClientWebsocket
-
- WebSocketStream verbose:true.
- WebSocketStream verboseProtocol:true.
-
- WebSocketStream verbose:false.
- WebSocketStream verboseProtocol:false.
- "
-
- |startTimestamp webSocket mask masked unmasked|
-
- startTimestamp := Timestamp now.
- webSocket := WebSocketStream new.
- mask := #[12 214 166 43].
-
- self allData do:[:eachData |
- masked := webSocket
- maskPayload:eachData
- mask:mask.
-
- unmasked := webSocket
- maskPayload:masked
- mask:mask.
-
- self assert:unmasked = eachData asByteArray.
- ].
-
- Transcript showCR:(Timestamp now - startTimestamp) printString.
+ self
+ maskAndUnmaskData:self allData
+ doAssert:true.
"Created: / 20-01-2020 / 15:08:27 / Stefan Reise"
- "Modified (comment): / 20-01-2020 / 18:09:11 / Stefan Reise"
+ "Modified: / 22-01-2020 / 16:22:48 / Stefan Reise"
+!
+
+testMask100
+ self
+ maskAndUnmaskData:self byteArray100
+ doAssert:true.
+
+ "Created: / 22-01-2020 / 15:41:29 / Stefan Reise"
+!
+
+testMask500
+ self
+ maskAndUnmaskData:self byteArray500
+ doAssert:true.
+
+ "Created: / 22-01-2020 / 15:41:35 / Stefan Reise"
!
testPing
"
- call the following method in case the sockets did get corrupted
- self resetServerAndClientWebsocket
+ !! call the following method in case the sockets did get corrupted !!
+ self resetServerAndClientWebsocket
WebSocketStream verbose:true.
WebSocketStream verboseProtocol:true.
@@ -452,7 +610,29 @@
self assert:pingTimeDuration notNil.
"Created: / 17-01-2020 / 13:43:58 / Stefan Reise"
- "Modified (comment): / 20-01-2020 / 18:09:16 / Stefan Reise"
+ "Modified (comment): / 22-01-2020 / 15:25:11 / Stefan Reise"
+! !
+
+!WebSocketTest methodsFor:'tests speed'!
+
+testMask100Speed
+ self
+ assert:(self
+ maskAndUnmaskData:self byteArray100
+ doAssert:false)
+ < 10 seconds.
+
+ "Created: / 22-01-2020 / 15:49:01 / Stefan Reise"
+!
+
+testMask500Speed
+ self
+ assert:(self
+ maskAndUnmaskData:self byteArray500
+ doAssert:false)
+ < 50 seconds.
+
+ "Created: / 22-01-2020 / 15:48:52 / Stefan Reise"
! !
!WebSocketTest methodsFor:'zzz'!