[squeak-dev] The Trunk: NetworkTests-eem.60.mcz
commits at source.squeak.org
commits at source.squeak.org
Fri Oct 9 08:20:32 UTC 2020
Eliot Miranda uploaded a new version of NetworkTests to project The Trunk:
http://source.squeak.org/trunk/NetworkTests-eem.60.mcz
==================== Summary ====================
Name: NetworkTests-eem.60
Author: eem
Time: 9 October 2020, 1:20:30.75953 am
UUID: 82de62f4-5a28-47ff-93f6-b712a39d43e9
Ancestors: NetworkTests-eem.59
Add a TCP version of the testSocketReuse test which shows a bad bug in macOS that had to be oatched in the VM.
=============== Diff against NetworkTests-eem.59 ===============
Item was changed:
----- Method: SocketTest>>testSocketReuse (in category 'tests') -----
testSocketReuse
+ "Test for SO_REUSEADDR/SO_REUSEPORT. Should probably be called testUDPSocketReuse.
+ c.f. testTCPSocketReuse"
- "Test for SO_REUSEADDR/SO_REUSEPORT"
| udp1 udp2 sendProc recvProc |
[
| address port opt send1 recv2 received sent |
address := #[255 255 255 255]. "broadcast"
port := 31259.
udp1 := Socket newUDP.
udp1 setOption: 'SO_REUSEADDR' value: 1.
self assert: 0 equals: udp1 socketError description: 'Error occured while setting SO_REUSEADDR'.
opt := udp1 getOption: 'SO_REUSEADDR'.
self assert: opt first isZero & opt last isZero not description: 'SO_REUSEADDR couldn''t be set'.
udp1 setOption: 'SO_REUSEPORT' value: 1.
self assert: 0 equals: udp1 socketError description: 'Error occured while setting SO_REUSEPORT'.
opt := udp1 getOption: 'SO_REUSEPORT'.
self assert: opt first isZero & opt last isZero not description: 'SO_REUSEPORT couldn''t be set'.
udp1 setPort: port.
self assert: port equals: udp1 localPort.
udp1 setOption: 'SO_BROADCAST' value: 1.
send1 := UUID new.
udp2 := Socket newUDP.
udp2 setOption: 'SO_REUSEADDR' value: 1.
self assert: 0 equals: udp2 socketError.
udp2 setOption: 'SO_REUSEPORT' value: 1.
self assert: 0 equals: udp2 socketError.
udp2 setPort: port.
self assert: port equals: udp2 localPort.
udp2 setOption: 'SO_BROADCAST' value: 1.
recv2 := UUID new.
received := 0.
recvProc := [
[received < 16] whileTrue:[
received := received + (udp2 receiveDataInto: recv2 startingAt: received + 1)
"No need to yield here, because #receiveDataInto:startingAt: will either wait on the readSemaphore of the socket or signal an error." ]
] newProcess.
sendProc := [
udp1 setPeer: address port: port.
sent := (udp1 sendSomeData: send1 startIndex: 1 count: 16 for: 1).
] newProcess.
recvProc resume.
sendProc resume.
(Delay forMilliseconds: 200) wait.
self
assert: sendProc isTerminated description: 'sendProc hasn''t terminated till the deadline';
assert: recvProc isTerminated description: 'recvProc hasn''t terminated till the deadline';
assert: 16 equals: sent description: ('{1} bytes were sent instead of 16' format: { sent });
assert: send1 equals: recv2 description: 'sent and received bytes differ'
] ensure:[
udp1 ifNotNil: [ udp1 destroy ].
udp2 ifNotNil: [ udp2 destroy ].
sendProc ifNotNil: [ sendProc terminate ].
recvProc ifNotNil: [ recvProc terminate ]
].
!
Item was added:
+ ----- Method: SocketTest>>testTCPSocketReuse (in category 'tests') -----
+ testTCPSocketReuse
+ "Test for SO_REUSEADDR/SO_REUSEPORT using TCP sockets. c.f. testSocketReuse"
+
+ | tcpSend tcpRecv sendProcess recvProcess |
+ [
+ | address port opt send1 recv2 sent |
+ address := NetNameResolver addressForName: '127.0.0.1' timeout: 20.
+ port := 31259.
+ tcpSend := Socket newTCP.
+ tcpSend setOption: 'SO_REUSEADDR' value: 1.
+ self assert: 0 equals: tcpSend socketError description: 'Error occured while setting SO_REUSEADDR'.
+ opt := tcpSend getOption: 'SO_REUSEADDR'.
+ self assert: opt first isZero & opt last isZero not description: 'SO_REUSEADDR couldn''t be set'.
+ tcpSend setOption: 'SO_REUSEPORT' value: 1.
+ self assert: 0 equals: tcpSend socketError description: 'Error occured while setting SO_REUSEPORT'.
+ opt := tcpSend getOption: 'SO_REUSEPORT'.
+ self assert: opt first isZero & opt last isZero not description: 'SO_REUSEPORT couldn''t be set'.
+ "tcpSend setOption: 'TCP_NODELAY' value: 1."
+ send1 := UUID new.
+
+ tcpRecv := Socket newTCP.
+ tcpRecv setOption: 'SO_REUSEADDR' value: 1.
+ self assert: 0 equals: tcpRecv socketError.
+ tcpRecv setOption: 'SO_REUSEPORT' value: 1.
+ self assert: 0 equals: tcpRecv socketError.
+ tcpRecv setPort: port.
+ self assert: port equals: tcpRecv localPort.
+ recv2 := UUID new.
+
+ [| received |
+ recvProcess := Processor activeProcess.
+ received := 0.
+ tcpRecv waitForConnectionFor: 200.
+ [received < 16] whileTrue:
+ ["No need to yield here, because #receiveDataInto:startingAt: will either wait on the readSemaphore of the socket or signal an error."
+ received := received + (tcpRecv receiveDataInto: recv2 startingAt: received + 1)]] fork.
+ [sendProcess := Processor activeProcess.
+ tcpSend connectTo: address port: port.
+ sent := tcpSend sendData: send1] fork.
+ (Delay forMilliseconds: 200) wait.
+ self
+ assert: sendProcess isTerminated description: 'sendProc hasn''t terminated till the deadline';
+ assert: recvProcess isTerminated description: 'recvProc hasn''t terminated till the deadline';
+ assert: 16 equals: sent description: ('{1} bytes were sent instead of 16' format: { sent });
+ assert: send1 equals: recv2 description: 'sent and received bytes differ']
+ ensure:
+ [tcpSend ifNotNil: [ tcpSend destroy ].
+ tcpRecv ifNotNil: [ tcpRecv destroy ].
+ sendProcess ifNotNil: [ sendProcess terminate ].
+ recvProcess ifNotNil: [ recvProcess terminate ]]!
More information about the Squeak-dev
mailing list
|