RegressionTests__WebSocketTest.st
changeset 2546 c4dbc7a9249b
parent 2545 56d15e80d7c3
child 2547 3aa44eca7ca3
equal deleted inserted replaced
2545:56d15e80d7c3 2546:c4dbc7a9249b
   112     ^ ByteArray new:100 * 1024 * 1024
   112     ^ ByteArray new:100 * 1024 * 1024
   113 
   113 
   114     "Created: / 22-01-2020 / 15:42:28 / Stefan Reise"
   114     "Created: / 22-01-2020 / 15:42:28 / Stefan Reise"
   115 !
   115 !
   116 
   116 
   117 byteArray500
       
   118     ^ ByteArray new:500 * 1024 * 1024
       
   119 
       
   120     "Created: / 22-01-2020 / 15:42:32 / Stefan Reise"
       
   121 !
       
   122 
       
   123 data100
   117 data100
   124     ^ String new:100 * 1024 * 1024
   118     ^ String new:100 * 1024 * 1024
   125 
   119 
   126     "Created: / 22-01-2020 / 15:40:35 / Stefan Reise"
   120     "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 !
   121 !
   134 
   122 
   135 dataWithLength0AndFrameHash
   123 dataWithLength0AndFrameHash
   136     ^ #(
   124     ^ #(
   137         '' 
   125         '' 
   491 
   479 
   492     "Created: / 22-01-2020 / 16:39:15 / Stefan Reise"
   480     "Created: / 22-01-2020 / 16:39:15 / Stefan Reise"
   493     "Modified (comment): / 23-01-2020 / 11:59:47 / Stefan Reise"
   481     "Modified (comment): / 23-01-2020 / 11:59:47 / Stefan Reise"
   494 !
   482 !
   495 
   483 
   496 testCommunication100WithMasking
   484 testCommunication100Speed
   497     "
   485     "
   498         !! call the following method in case the sockets did get corrupted !!
   486         !! call the following method in case the sockets did get corrupted !!
   499         self resetServerAndClientWebsocket              
   487         self resetServerAndClientWebsocket              
   500 
   488 
   501         WebSocketStream verbose:true.
   489         WebSocketStream verbose:true.
   502         WebSocketStream verboseSpeed:true.     
       
   503         WebSocketStream verboseProtocol:true.
   490         WebSocketStream verboseProtocol:true.
   504 
   491 
   505         WebSocketStream verbose:false.
   492         WebSocketStream verbose:false.
   506         WebSocketStream verboseSpeed:false.
       
   507         WebSocketStream verboseProtocol:false.
   493         WebSocketStream verboseProtocol:false.
   508 
   494 
   509         WebSocketStream maxBytesPerFrame:1024. 
   495         WebSocketStream maxBytesPerFrame:1024. 
   510         WebSocketStream maxBytesPerFrame:nil.      
   496         WebSocketStream maxBytesPerFrame:nil.      
   511     "
   497     "
   512 
   498 
   513     self 
   499     self 
   514         withData:self byteArray100
   500         communicationWithData:self data100
   515         do:[:data |
   501         doAssert:false.
   516             self clientWebSocket nextPut:data.
   502 
   517             self serverWebSocket next.
   503     "Created: / 23-01-2020 / 11:32:34 / Stefan Reise"
   518         ].
       
   519 
       
   520     "Created: / 28-01-2020 / 13:36:57 / Stefan Reise"
       
   521     "Modified: / 31-01-2020 / 15:52:20 / Stefan Reise"
       
   522 !
       
   523 
       
   524 testCommunication100WithoutMasking
       
   525     "
       
   526         !! call the following method in case the sockets did get corrupted !!
       
   527         self resetServerAndClientWebsocket              
       
   528 
       
   529         WebSocketStream verbose:true.
       
   530         WebSocketStream verboseProtocol:true.
       
   531 
       
   532         WebSocketStream verbose:false.
       
   533         WebSocketStream verboseProtocol:false.
       
   534 
       
   535         WebSocketStream maxBytesPerFrame:1024. 
       
   536         WebSocketStream maxBytesPerFrame:nil.      
       
   537     "
       
   538 
       
   539     self 
       
   540         withData:self byteArray100
       
   541         do:[:data |
       
   542             self serverWebSocket nextPut:data.
       
   543             self clientWebSocket next.             
       
   544         ].
       
   545 
       
   546     "Created: / 28-01-2020 / 13:35:50 / Stefan Reise"
       
   547     "Modified: / 31-01-2020 / 15:52:31 / Stefan Reise"
       
   548 !
       
   549 
       
   550 testCommunication500
       
   551     "
       
   552         !! call the following method in case the sockets did get corrupted !!
       
   553         self resetServerAndClientWebsocket              
       
   554 
       
   555         WebSocketStream verbose:true.
       
   556         WebSocketStream verboseProtocol:true.
       
   557 
       
   558         WebSocketStream verbose:false.
       
   559         WebSocketStream verboseProtocol:false.
       
   560 
       
   561         WebSocketStream maxBytesPerFrame:1024. 
       
   562         WebSocketStream maxBytesPerFrame:nil.      
       
   563     "
       
   564 
       
   565     self 
       
   566         communicationWithData:self data500
       
   567         doAssert:true.
       
   568 
       
   569     "Created: / 22-01-2020 / 16:39:19 / Stefan Reise"
       
   570     "Modified (comment): / 23-01-2020 / 11:59:52 / Stefan Reise"
       
   571 !
   504 !
   572 
   505 
   573 testCommunicationByteArray100
   506 testCommunicationByteArray100
   574     "
   507     "
   575         !! call the following method in case the sockets did get corrupted !!
   508         !! call the following method in case the sockets did get corrupted !!
   591 
   524 
   592     "Created: / 22-01-2020 / 17:45:53 / Stefan Reise"
   525     "Created: / 22-01-2020 / 17:45:53 / Stefan Reise"
   593     "Modified (comment): / 23-01-2020 / 11:59:55 / Stefan Reise"
   526     "Modified (comment): / 23-01-2020 / 11:59:55 / Stefan Reise"
   594 !
   527 !
   595 
   528 
   596 testCommunicationByteArray500
   529 testCommunicationFilename
   597     "
   530     "
   598         !! call the following method in case the sockets did get corrupted !!
   531         !! call the following method in case the sockets did get corrupted !!
   599         self resetServerAndClientWebsocket              
   532         self resetServerAndClientWebsocket              
   600 
   533 
   601         WebSocketStream verbose:true.
   534         WebSocketStream verbose:true.
   606 
   539 
   607         WebSocketStream maxBytesPerFrame:1024. 
   540         WebSocketStream maxBytesPerFrame:1024. 
   608         WebSocketStream maxBytesPerFrame:nil.      
   541         WebSocketStream maxBytesPerFrame:nil.      
   609     "
   542     "
   610 
   543 
       
   544     |tempFile|
       
   545 
       
   546     tempFile := Filename newTemporary.
       
   547     tempFile contents:self data100.
       
   548 
   611     self 
   549     self 
   612         communicationWithData:self byteArray500
   550         communicationWithData:tempFile
   613         doAssert:true.
   551         doAssert:true.
   614 
   552 
   615     "Created: / 22-01-2020 / 17:45:53 / Stefan Reise"
       
   616     "Modified (comment): / 23-01-2020 / 11:59:55 / Stefan Reise"
       
   617 !
       
   618 
       
   619 testCommunicationFilename
       
   620     "
       
   621         !! call the following method in case the sockets did get corrupted !!
       
   622         self resetServerAndClientWebsocket              
       
   623 
       
   624         WebSocketStream verbose:true.
       
   625         WebSocketStream verboseProtocol:true.
       
   626 
       
   627         WebSocketStream verbose:false.
       
   628         WebSocketStream verboseProtocol:false.
       
   629 
       
   630         WebSocketStream maxBytesPerFrame:1024. 
       
   631         WebSocketStream maxBytesPerFrame:nil.      
       
   632     "
       
   633 
       
   634 
       
   635     self halt.
       
   636 
       
   637 "/    self 
       
   638 "/        communicationWithData:'C:\Users\Stefan Reise\Desktop\NUnit.txt' asFilename
       
   639 "/        doAssert:true.
       
   640 
       
   641 
       
   642     self 
       
   643         communicationWithData:'C:\Users\Stefan Reise\Downloads\MobileTestingSupplement.exe' asFilename
       
   644         doAssert:true.
       
   645 
       
   646     "Created: / 27-01-2020 / 15:07:37 / Stefan Reise"
   553     "Created: / 27-01-2020 / 15:07:37 / Stefan Reise"
   647     "Modified: / 31-01-2020 / 15:52:57 / Stefan Reise"
   554     "Modified (format): / 04-02-2020 / 12:22:23 / Stefan Reise"
   648 !
   555 !
   649 
   556 
   650 testCommunicationSmallFrameSize
   557 testCommunicationSmallFrameSize
   651     "
   558     "
   652         !! call the following method in case the sockets did get corrupted !!
   559         !! call the following method in case the sockets did get corrupted !!
   783         doAssert:true.
   690         doAssert:true.
   784 
   691 
   785     "Created: / 22-01-2020 / 15:41:29 / Stefan Reise"
   692     "Created: / 22-01-2020 / 15:41:29 / Stefan Reise"
   786 !
   693 !
   787 
   694 
   788 testMask500
       
   789     self 
       
   790         maskAndUnmaskData:self byteArray500
       
   791         doAssert:true.
       
   792 
       
   793     "Created: / 22-01-2020 / 15:41:35 / Stefan Reise"
       
   794 !
       
   795 
       
   796 testOnEchoServer
       
   797     "/ empty (1) and big data (>5) is not supported by echo server
       
   798     (self allData from:2 to:5) do:[:eachData |
       
   799         self assertOnEchoServer:eachData.
       
   800     ].
       
   801 
       
   802     "Created: / 15-01-2020 / 15:55:27 / Stefan Reise"
       
   803     "Modified: / 04-02-2020 / 12:09:52 / Stefan Reise"
       
   804 !
       
   805 
       
   806 testParallelSocketWrite
       
   807     "
       
   808         !! call the following method in case the sockets did get corrupted !!
       
   809         self resetServerAndClientWebsocket           
       
   810 
       
   811         WebSocketStream verbose:true.
       
   812         WebSocketStream verboseProtocol:true.
       
   813 
       
   814         WebSocketStream verbose:false.
       
   815         WebSocketStream verboseProtocol:false.   
       
   816 
       
   817         WebSocketStream maxBytesPerFrame:8178. 
       
   818         WebSocketStream maxBytesPerFrame:nil.      
       
   819     "
       
   820 
       
   821     ^ self 
       
   822         withData:self data100
       
   823         do:[:eachData |
       
   824             self clientWebSocket nextPut:eachData.
       
   825             self serverWebSocket nextPut:eachData.
       
   826         ]
       
   827 
       
   828     "Created: / 23-01-2020 / 11:47:47 / Stefan Reise"
       
   829     "Modified (comment): / 23-01-2020 / 14:24:42 / Stefan Reise"
       
   830 !
       
   831 
       
   832 testPing
       
   833     "
       
   834         !! call the following method in case the sockets did get corrupted !!
       
   835         self resetServerAndClientWebsocket           
       
   836 
       
   837         WebSocketStream verbose:true.
       
   838         WebSocketStream verboseProtocol:true.
       
   839 
       
   840         WebSocketStream verbose:false.             
       
   841         WebSocketStream verboseProtocol:false.   
       
   842     "
       
   843 
       
   844     |pingTimeDuration|
       
   845 
       
   846     pingTimeDuration := self clientWebSocket ping.
       
   847     Transcript showCR:pingTimeDuration printString.
       
   848     self assert:pingTimeDuration notNil.
       
   849 
       
   850     pingTimeDuration := self serverWebSocket ping.
       
   851     Transcript showCR:pingTimeDuration printString.
       
   852     self assert:pingTimeDuration notNil.
       
   853 
       
   854     "Created: / 17-01-2020 / 13:43:58 / Stefan Reise"
       
   855     "Modified (comment): / 22-01-2020 / 15:25:11 / Stefan Reise"
       
   856 ! !
       
   857 
       
   858 !WebSocketTest methodsFor:'tests speed'!
       
   859 
       
   860 testCommunication100Speed
       
   861     "
       
   862         !! call the following method in case the sockets did get corrupted !!
       
   863         self resetServerAndClientWebsocket              
       
   864 
       
   865         WebSocketStream verbose:true.
       
   866         WebSocketStream verboseProtocol:true.
       
   867 
       
   868         WebSocketStream verbose:false.
       
   869         WebSocketStream verboseProtocol:false.
       
   870 
       
   871         WebSocketStream maxBytesPerFrame:1024. 
       
   872         WebSocketStream maxBytesPerFrame:nil.      
       
   873     "
       
   874 
       
   875     self 
       
   876         communicationWithData:self data100
       
   877         doAssert:false.
       
   878 
       
   879     "Created: / 23-01-2020 / 11:32:34 / Stefan Reise"
       
   880 !
       
   881 
       
   882 testMask100Speed  
   695 testMask100Speed  
   883     self 
   696     self 
   884         assert:(self 
   697         assert:(self 
   885             maskAndUnmaskData:self byteArray100
   698             maskAndUnmaskData:self byteArray100
   886             doAssert:false)
   699             doAssert:false)
   887                 < 10 seconds.
   700                 < 10 seconds.
   888 
   701 
   889     "Created: / 22-01-2020 / 15:49:01 / Stefan Reise"
   702     "Created: / 22-01-2020 / 15:49:01 / Stefan Reise"
   890 !
   703 !
   891 
   704 
   892 testMask500Speed  
   705 testOnEchoServer
   893     self 
   706     "/ empty (1) and big data (>5) is not supported by echo server
   894         assert:(self 
   707     (self allData from:2 to:5) do:[:eachData |
   895             maskAndUnmaskData:self byteArray500
   708         self assertOnEchoServer:eachData.
   896             doAssert:false)
   709     ].
   897                 < 50 seconds.
   710 
   898 
   711     "Created: / 15-01-2020 / 15:55:27 / Stefan Reise"
   899     "Created: / 22-01-2020 / 15:48:52 / Stefan Reise"
   712     "Modified: / 04-02-2020 / 12:09:52 / Stefan Reise"
       
   713 !
       
   714 
       
   715 testParallelSocketWrite
       
   716     "
       
   717         !! call the following method in case the sockets did get corrupted !!
       
   718         self resetServerAndClientWebsocket           
       
   719 
       
   720         WebSocketStream verbose:true.
       
   721         WebSocketStream verboseProtocol:true.
       
   722 
       
   723         WebSocketStream verbose:false.
       
   724         WebSocketStream verboseProtocol:false.   
       
   725 
       
   726         WebSocketStream maxBytesPerFrame:8178. 
       
   727         WebSocketStream maxBytesPerFrame:nil.      
       
   728     "
       
   729 
       
   730     ^ self 
       
   731         withData:self data100
       
   732         do:[:eachData |
       
   733             self clientWebSocket nextPut:eachData.
       
   734             self serverWebSocket nextPut:eachData.
       
   735 
       
   736             Delay waitForSeconds:20.
       
   737 
       
   738             self clientWebSocket next.
       
   739             self serverWebSocket next.
       
   740         ].
       
   741 
       
   742     "Created: / 23-01-2020 / 11:47:47 / Stefan Reise"
       
   743     "Modified: / 04-02-2020 / 12:26:59 / Stefan Reise"
       
   744 !
       
   745 
       
   746 testPing
       
   747     "
       
   748         !! call the following method in case the sockets did get corrupted !!
       
   749         self resetServerAndClientWebsocket           
       
   750 
       
   751         WebSocketStream verbose:true.
       
   752         WebSocketStream verboseProtocol:true.
       
   753 
       
   754         WebSocketStream verbose:false.             
       
   755         WebSocketStream verboseProtocol:false.   
       
   756     "
       
   757 
       
   758     |pingTimeDuration|
       
   759 
       
   760     pingTimeDuration := self clientWebSocket ping.
       
   761     Transcript showCR:pingTimeDuration printString.
       
   762     self assert:pingTimeDuration notNil.
       
   763 
       
   764     pingTimeDuration := self serverWebSocket ping.
       
   765     Transcript showCR:pingTimeDuration printString.
       
   766     self assert:pingTimeDuration notNil.
       
   767 
       
   768     "Created: / 17-01-2020 / 13:43:58 / Stefan Reise"
       
   769     "Modified (comment): / 22-01-2020 / 15:25:11 / Stefan Reise"
   900 ! !
   770 ! !
   901 
   771 
   902 !WebSocketTest::DemoWebSocketService class methodsFor:'constants'!
   772 !WebSocketTest::DemoWebSocketService class methodsFor:'constants'!
   903 
   773 
   904 defaultPort
   774 defaultPort