"{ Encoding: utf8 }"
"{ Package: 'stx:goodies/regression' }"
"{ NameSpace: RegressionTests }"
TestCase subclass:#SocketTests
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'tests-Regression-Streams'
!
!SocketTests methodsFor:'tests - open-close'!
test10_concurrentOpenClose
|p1 p2 sock host port n1 n2|
host := 'download.exept.de'.
port := 80.
n1 := n2 := 0.
p1 :=
[
[true] whileTrue:[
sock := Socket newTCPclientToHost:host port:port.
self assert:(sock notNil).
Processor yield.
n1 := n1 + 1.
sock close
]
] newProcess.
p2 :=
[
[true] whileTrue:[
sock := Socket newTCPclientToHost:host port:port.
self assert:(sock notNil).
Processor yield.
n2 := n2 + 1.
sock close
]
] newProcess.
p1 resume.
p2 resume.
Delay waitForSeconds:20.
p1 terminate.
p2 terminate.
Transcript showCR:'n1: %1; n2: %2' with:n1 with:n2.
self assert:(n1 > 0).
self assert:(n2 > 0).
"Created: / 29-11-2011 / 14:43:57 / cg"
"Modified: / 10-10-2017 / 12:15:10 / cg"
"Modified: / 10-10-2017 / 12:55:50 / stefan"
!
test11_concurrentOpenClose
"using a non-existing host name (hoping that the connect will take longer then,
and we can enforce concurrent execution)"
|p1 p2 sock port n1 n2 nerr1 nerr2|
port := 80.
n1 := n2 := 0.
nerr1 := nerr2 := 0.
p1 :=
[
|host|
[true] whileTrue:[
host := 'bla1.nonexisting-%1.de' bindWith:(UUID genRandomUUID).
HostNameLookupError handle:[:ex |
nerr1 := nerr1 + 1.
] do:[
sock := Socket newTCPclientToHost:host port:port.
self assert:(sock notNil).
n1 := n1 + 1.
Transcript showCR:host.
sock close
].
Processor yield.
]
] newProcess.
p2 :=
[
|host|
[true] whileTrue:[
host := 'bla2.nonexisting-%1.de' bindWith:(UUID genRandomUUID).
HostNameLookupError handle:[:ex |
nerr2 := nerr2 + 1.
] do:[
sock := Socket newTCPclientToHost:host port:port.
self assert:(sock notNil).
Transcript showCR:host.
n2 := n2 + 1.
sock close
].
Processor yield.
]
] newProcess.
p1 priority:Processor userBackgroundPriority; resume.
p2 priority:Processor userBackgroundPriority; resume.
Delay waitForSeconds:10.
p1 terminate.
p2 terminate.
Transcript showCR:'n1: %1; n2: %2' with:n1 with:n2.
Transcript showCR:'nerr1: %1; nerr2: %2' with:nerr1 with:nerr1.
self assert:(n1 = 0).
self assert:(n2 = 0).
self assert:(nerr1 > 0).
self assert:(nerr2 > 0).
"Created: / 29-11-2011 / 18:17:04 / cg"
"Modified: / 10-10-2017 / 12:18:08 / cg"
"Modified: / 10-10-2017 / 13:45:22 / stefan"
! !
!SocketTests methodsFor:'tests - socket address'!
test20_localAddress
"fails on MAC-osx"
|addr nm|
addr := IPSocketAddress localHost.
self assert:(addr hostAddress = #[127 0 0 1]).
nm := addr hostName.
self assert:(nm notEmptyOrNil).
addr := IPSocketAddress addressString:'127.0.0.1'.
self assert:(addr hostAddress = #[127 0 0 1]).
addr port:51121.
nm := addr hostName.
self assert:(nm notEmptyOrNil).
self assert:(addr hostAddress = #[127 0 0 1]).
self assert:(addr port = 51121).
"Modified: / 10-10-2017 / 12:57:49 / stefan"
! !
!SocketTests class methodsFor:'documentation'!
version
^ '$Header$'
!
version_CVS
^ '$Header$'
! !