author | Claus Gittinger <cg@exept.de> |
Thu, 17 May 2018 23:11:54 +0200 | |
changeset 1931 | bdc99c92a5a6 |
parent 1721 | ea19dde999b3 |
permissions | -rw-r--r-- |
1721 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1447 | 3 |
"{ Package: 'stx:goodies/regression' }" |
646 | 4 |
|
5 |
"{ NameSpace: RegressionTests }" |
|
6 |
||
7 |
TestCase subclass:#SocketTests |
|
8 |
instanceVariableNames:'' |
|
9 |
classVariableNames:'' |
|
10 |
poolDictionaries:'' |
|
1084 | 11 |
category:'tests-Regression-Streams' |
646 | 12 |
! |
13 |
||
14 |
||
15 |
!SocketTests methodsFor:'tests - open-close'! |
|
16 |
||
17 |
test10_concurrentOpenClose |
|
18 |
|p1 p2 sock host port n1 n2| |
|
19 |
||
1721 | 20 |
host := 'download.exept.de'. |
646 | 21 |
port := 80. |
22 |
n1 := n2 := 0. |
|
23 |
||
1447 | 24 |
p1 := |
1715 | 25 |
[ |
26 |
[true] whileTrue:[ |
|
27 |
sock := Socket newTCPclientToHost:host port:port. |
|
28 |
self assert:(sock notNil). |
|
29 |
Processor yield. |
|
30 |
n1 := n1 + 1. |
|
31 |
sock close |
|
32 |
] |
|
33 |
] newProcess. |
|
646 | 34 |
|
1447 | 35 |
p2 := |
1715 | 36 |
[ |
37 |
[true] whileTrue:[ |
|
38 |
sock := Socket newTCPclientToHost:host port:port. |
|
39 |
self assert:(sock notNil). |
|
40 |
Processor yield. |
|
41 |
n2 := n2 + 1. |
|
42 |
sock close |
|
43 |
] |
|
44 |
] newProcess. |
|
646 | 45 |
|
46 |
p1 resume. |
|
47 |
p2 resume. |
|
48 |
||
49 |
Delay waitForSeconds:20. |
|
50 |
p1 terminate. |
|
51 |
p2 terminate. |
|
52 |
||
1721 | 53 |
Transcript showCR:'n1: %1; n2: %2' with:n1 with:n2. |
1716 | 54 |
self assert:(n1 > 0). |
55 |
self assert:(n2 > 0). |
|
646 | 56 |
|
57 |
"Created: / 29-11-2011 / 14:43:57 / cg" |
|
1716 | 58 |
"Modified: / 10-10-2017 / 12:15:10 / cg" |
1721 | 59 |
"Modified: / 10-10-2017 / 12:55:50 / stefan" |
647
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
60 |
! |
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
61 |
|
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
62 |
test11_concurrentOpenClose |
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
63 |
"using a non-existing host name (hoping that the connect will take longer then, |
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
64 |
and we can enforce concurrent execution)" |
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
65 |
|
1716 | 66 |
|p1 p2 sock port n1 n2 nerr1 nerr2| |
647
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
67 |
|
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
68 |
port := 80. |
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
69 |
n1 := n2 := 0. |
1716 | 70 |
nerr1 := nerr2 := 0. |
71 |
||
1447 | 72 |
p1 := |
1715 | 73 |
[ |
74 |
|host| |
|
647
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
75 |
|
1715 | 76 |
[true] whileTrue:[ |
1721 | 77 |
host := 'bla1.nonexisting-%1.de' bindWith:(UUID genRandomUUID). |
1715 | 78 |
HostNameLookupError handle:[:ex | |
1716 | 79 |
nerr1 := nerr1 + 1. |
1715 | 80 |
] do:[ |
81 |
sock := Socket newTCPclientToHost:host port:port. |
|
1716 | 82 |
self assert:(sock notNil). |
1715 | 83 |
n1 := n1 + 1. |
1721 | 84 |
Transcript showCR:host. |
1715 | 85 |
sock close |
86 |
]. |
|
1721 | 87 |
Processor yield. |
1715 | 88 |
] |
89 |
] newProcess. |
|
647
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
90 |
|
1447 | 91 |
p2 := |
1715 | 92 |
[ |
93 |
|host| |
|
647
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
94 |
|
1715 | 95 |
[true] whileTrue:[ |
1721 | 96 |
host := 'bla2.nonexisting-%1.de' bindWith:(UUID genRandomUUID). |
1715 | 97 |
HostNameLookupError handle:[:ex | |
1716 | 98 |
nerr2 := nerr2 + 1. |
1715 | 99 |
] do:[ |
100 |
sock := Socket newTCPclientToHost:host port:port. |
|
1716 | 101 |
self assert:(sock notNil). |
1721 | 102 |
Transcript showCR:host. |
1715 | 103 |
n2 := n2 + 1. |
104 |
sock close |
|
1721 | 105 |
]. |
106 |
Processor yield. |
|
1715 | 107 |
] |
108 |
] newProcess. |
|
647
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
109 |
|
1721 | 110 |
p1 priority:Processor userBackgroundPriority; resume. |
111 |
p2 priority:Processor userBackgroundPriority; resume. |
|
647
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
112 |
|
1721 | 113 |
Delay waitForSeconds:10. |
647
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
114 |
p1 terminate. |
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
115 |
p2 terminate. |
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
116 |
|
1721 | 117 |
Transcript showCR:'n1: %1; n2: %2' with:n1 with:n2. |
118 |
Transcript showCR:'nerr1: %1; nerr2: %2' with:nerr1 with:nerr1. |
|
1716 | 119 |
self assert:(n1 = 0). |
120 |
self assert:(n2 = 0). |
|
121 |
self assert:(nerr1 > 0). |
|
122 |
self assert:(nerr2 > 0). |
|
647
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
123 |
|
588836b3ec73
added: #test11_concurrentOpenClose
Claus Gittinger <cg@exept.de>
parents:
646
diff
changeset
|
124 |
"Created: / 29-11-2011 / 18:17:04 / cg" |
1716 | 125 |
"Modified: / 10-10-2017 / 12:18:08 / cg" |
1721 | 126 |
"Modified: / 10-10-2017 / 13:45:22 / stefan" |
646 | 127 |
! ! |
128 |
||
1266
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
129 |
!SocketTests methodsFor:'tests - socket address'! |
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
130 |
|
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
131 |
test20_localAddress |
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
132 |
"fails on MAC-osx" |
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
133 |
|
1721 | 134 |
|addr nm| |
1266
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
135 |
|
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
136 |
addr := IPSocketAddress localHost. |
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
137 |
self assert:(addr hostAddress = #[127 0 0 1]). |
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
138 |
|
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
139 |
nm := addr hostName. |
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
140 |
self assert:(nm notEmptyOrNil). |
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
141 |
|
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
142 |
addr := IPSocketAddress addressString:'127.0.0.1'. |
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
143 |
self assert:(addr hostAddress = #[127 0 0 1]). |
1447 | 144 |
addr port:51121. |
1266
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
145 |
nm := addr hostName. |
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
146 |
self assert:(nm notEmptyOrNil). |
1267
a98d46cee5f9
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
147 |
self assert:(addr hostAddress = #[127 0 0 1]). |
a98d46cee5f9
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1266
diff
changeset
|
148 |
self assert:(addr port = 51121). |
1721 | 149 |
|
150 |
"Modified: / 10-10-2017 / 12:57:49 / stefan" |
|
1266
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
151 |
! ! |
ba8ef71776bd
class: RegressionTests::SocketTests
Claus Gittinger <cg@exept.de>
parents:
1084
diff
changeset
|
152 |
|
646 | 153 |
!SocketTests class methodsFor:'documentation'! |
154 |
||
155 |
version |
|
156 |
^ '$Header$' |
|
157 |
! |
|
158 |
||
159 |
version_CVS |
|
160 |
^ '$Header$' |
|
161 |
! ! |
|
1084 | 162 |