Issue 3350 in pharo: Network Tests

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue 3350 in pharo: Network Tests

pharo
Status: FixedWaitingToBePharoed
Owner: stephane.ducasse
Labels: Milestone-1.3

New issue 3350 by stephane.ducasse: Network Tests
http://code.google.com/p/pharo/issues/detail?id=3350

Item was changed:
  ----- Method: Socket>>localAddress (in category 'accessing') -----
  localAddress
+
+       self isWaitingForConnection ifFalse: [
+               self
+                       waitForConnectionFor: Socket standardTimeout
+                       ifTimedOut: [ ^ByteArray new: 4 ] ].
+       ^self primSocketLocalAddress: socketHandle!
-       self isWaitingForConnection
-               ifFalse: [[self waitForConnectionFor: Socket  
standardTimeout]
-                               on: ConnectionTimedOut
-                               do: [:ex | ^ ByteArray new: 4]].
-       ^ self primSocketLocalAddress: socketHandle!

Item was changed:
  ----- Method: Socket>>localPort (in category 'accessing') -----
  localPort
+
+       self isWaitingForConnection ifFalse: [
+               self
+                       waitForConnectionFor: Socket standardTimeout
+                       ifTimedOut: [ ^0] ].
-       self isWaitingForConnection
-               ifFalse: [[self waitForConnectionFor: Socket  
standardTimeout]
-                               on: ConnectionTimedOut
-                               do: [:ex | ^ 0]].
        ^ self primSocketLocalPort: socketHandle!

Item was changed:
  ----- Method: Socket>>waitForAcceptFor: (in category 'waiting') -----
  waitForAcceptFor: timeout
        "Wait and accept an incoming connection. Return nil if it falis"
+       self waitForConnectionFor: timeout ifTimedOut: [^ nil].
+       ^ self isConnected
-       [self waitForConnectionFor: timeout] on: ConnectionTimedOut do:  
[:ex | ^nil].
-       ^self isConnected
                ifTrue:[self accept]
                !

Item was changed:
  ----- Method: Socket>>waitForConnectionFor:ifTimedOut: (in  
category 'waiting') -----
  waitForConnectionFor: timeout ifTimedOut: timeoutBlock
        "Wait up until the given deadline for a connection to be  
established. Return true if it is established by the deadline, false if  
not."

+       | startTime msecsDelta msecsEllapsed status |
+       startTime := Time millisecondClockValue.
+       msecsDelta := (timeout * 1000) truncated.
-       | status deadline |
-       deadline := Socket deadlineSecs: timeout.
        status := self primSocketConnectionStatus: socketHandle.
+       [(status = WaitingForConnection) and: [(msecsEllapsed := Time  
millisecondsSince: startTime) < msecsDelta]]
-       [(status = WaitingForConnection) and: [Time millisecondClockValue <  
deadline]]
                whileTrue: [
+                       semaphore waitTimeoutMSecs: msecsDelta -  
msecsEllapsed.
-                       semaphore waitTimeoutMSecs: (deadline - Time  
millisecondClockValue).
                        status := self primSocketConnectionStatus:  
socketHandle].

+       status = Connected ifFalse: [^timeoutBlock value].
+       ^ true!
-       status = Connected ifFalse: [^timeoutBlock value]
- !

Item was changed:
  ----- Method: Socket>>waitForDataFor:ifClosed:ifTimedOut: (in  
category 'waiting') -----
  waitForDataFor: timeout ifClosed: closedBlock ifTimedOut: timedOutBlock
        "Wait for the given nr of seconds for data to arrive."
+
+       | startTime msecsDelta |
+       startTime := Time millisecondClockValue.
+       msecsDelta := (timeout * 1000) truncated.
+       [(Time millisecondsSince: startTime) < msecsDelta] whileTrue: [
+               (self primSocketReceiveDataAvailable: socketHandle)
+                       ifTrue: [^self].
+               self isConnected
+                       ifFalse: [^closedBlock value].
+               self readSemaphore waitTimeoutMSecs:
+                       (msecsDelta - (Time millisecondsSince: startTime)  
max: 0).
+       ].

-       | deadline |
-       deadline := Socket deadlineSecs: timeout.
-
-       [Time millisecondClockValue < deadline]
-               whileTrue: [
-                       (self primSocketReceiveDataAvailable: socketHandle)
-                               ifTrue: [^self].
-                       self isConnected
-                               ifFalse: [^closedBlock value].
-                       self readSemaphore waitTimeoutMSecs: (deadline -  
Time millisecondClockValue)].
-
        (self primSocketReceiveDataAvailable: socketHandle)
                ifFalse: [
                        self isConnected
                                ifTrue: [^timedOutBlock value]
+                               ifFalse: [^closedBlock value]].!
-                               ifFalse: [^closedBlock value]]!

Item was changed:
  ----- Method: Socket>>waitForDisconnectionFor: (in category 'waiting')  
-----
  waitForDisconnectionFor: timeout
        "Wait for the given nr of seconds for the connection to be broken.
        Return true if it is broken by the deadline, false if not.
        The client should know the connection is really going to be closed
        (e.g., because he has called 'close' to send a close request to the  
other end)
        before calling this method."

+       | startTime msecsDelta status |
+       startTime := Time millisecondClockValue.
+       msecsDelta := (timeout * 1000) truncated.
-       | status deadline |
        status := self primSocketConnectionStatus: socketHandle.
-       deadline := Socket deadlineSecs: timeout.
        [((status == Connected) or: [(status == ThisEndClosed)]) and:
+        [(Time millisecondsSince: startTime) < msecsDelta]] whileTrue: [
-        [Time millisecondClockValue < deadline]] whileTrue: [
                self discardReceivedData.
+               self readSemaphore waitTimeoutMSecs:
+                       (msecsDelta - (Time millisecondsSince: startTime)  
max: 0).
-               self readSemaphore waitTimeoutMSecs: (deadline - Time  
millisecondClockValue).
                status := self primSocketConnectionStatus: socketHandle].
+       ^ status ~= Connected!
-
-       ^ status ~= Connected
- !
Item was changed:
  ----- Method: Socket>>waitForSendDoneFor: (in category 'waiting') -----
  waitForSendDoneFor: timeout
        "Wait up until the given deadline for the current send operation to  
complete. Return true if it completes by the deadline, false if not."

+       | startTime msecsDelta msecsEllapsed sendDone |
+       startTime := Time millisecondClockValue.
+       msecsDelta := (timeout * 1000) truncated.
+       [(sendDone := self primSocketSendDone: socketHandle) not and: [  
self isConnected
-       | sendDone deadline |
-       deadline := Socket deadlineSecs: timeout.
-       [self isConnected & (sendDone := self primSocketSendDone:  
socketHandle) not
                        "Connection end and final data can happen fast, so  
test in this order"
+               and: [(msecsEllapsed := Time millisecondsSince: startTime)  
< msecsDelta]]] whileTrue: [
+                       self writeSemaphore waitTimeoutMSecs: msecsDelta -  
msecsEllapsed].
-               and: [Time millisecondClockValue < deadline]] whileTrue: [
-                       self writeSemaphore waitTimeoutMSecs: (deadline -  
Time millisecondClockValue)].

        ^ sendDone!

Item was changed:
  ----- Method: SocksSocket>>connectTo:port: (in category 'connection  
open/close') -----
  connectTo: hostAddress port: port
        self initializeNetwork.
        self shouldUseSocks
                ifFalse: [^super connectTo: hostAddress port: port].
        super connectTo: socksIP port: socksPort.
+       self waitForConnectionFor: Socket standardTimeout.
-       self waitForConnectionUntil: Socket standardDeadline.
        dstIP := hostAddress.
        dstPort := port.
        vers = 4
                ifTrue: [self connectSocks4]
                ifFalse: [self connectSocks5]
        !

Item was changed:
  ----- Method: SocksSocket>>connectToHostNamed:port: (in  
category 'connection open/close') -----
  connectToHostNamed: hostName port: port
        super connectTo: socksIP port: socksPort.
+       self waitForConnectionFor: Socket standardTimeout.
-       self waitForConnectionUntil: Socket standardDeadline.
        dstName := hostName.
        dstPort := port.
        vers = 4
                ifTrue: [self connectSocks4]
                ifFalse: [self connectSocks5]
        !


Reply | Threaded
Open this post in threaded view
|

Re: Issue 3350 in pharo: Network Tests

pharo

Comment #1 on issue 3350 by stephane.ducasse: Network Tests
http://code.google.com/p/pharo/issues/detail?id=3350

Two more SocketTests.

=============== Diff against NetworkTests-ar.21 ===============

Item was added:
+ ----- Method: SocketTest>>testDataReceive (in category 'tests') -----
+ testDataReceive
+       "Test data transfer and related methods"
+
+       self testDataSending.
+       "It can take a tad for the status change to be visible"
+       (Delay forMilliseconds: 200) wait.
+       self assert: serverSocket dataAvailable.
+       self assert: (serverSocket receiveData = 'Hello World').
+       self deny: (serverSocket dataAvailable).
+ !

Item was added:
+ ----- Method: SocketTest>>testDataSending (in category 'tests') -----
+ testDataSending
+       "Test data transfer and related methods"
+
+       self testServerAccept.
+       clientSocket sendData: 'Hello World'.
+       clientSocket waitForSendDoneFor: 2.
+       self assert: clientSocket sendDone.
+


Reply | Threaded
Open this post in threaded view
|

Re: Issue 3350 in pharo: Network Tests

pharo
Updates:
        Cc: stephane.ducasse

Comment #2 on issue 3350 by [hidden email]: Network Tests
http://code.google.com/p/pharo/issues/detail?id=3350

A SocketTest class has been introduced in Squeak 4.2.
It is 8 tests cases.
They are all green in Pharo 1.2 and Pharo 1.3.
We should integrate that in Pharo and preferably in 1.2 if it is still  
possible.

Thanks to Squeak people for these tests!



Attachments:
        SocketTest.st  3.3 KB


Reply | Threaded
Open this post in threaded view
|

Re: Issue 3350 in pharo: Network Tests

pharo
Updates:
        Status: Fixed
        Labels: Milestone-1.2

Comment #3 on issue 3350 by [hidden email]: Network Tests
http://code.google.com/p/pharo/issues/detail?id=3350

If they are green :)


Reply | Threaded
Open this post in threaded view
|

Re: Issue 3350 in pharo: Network Tests

pharo

Comment #4 on issue 3350 by [hidden email]: Network Tests
http://code.google.com/p/pharo/issues/detail?id=3350

in 12337

TODO: 1.3


Reply | Threaded
Open this post in threaded view
|

Re: Issue 3350 in pharo: Network Tests

pharo
Updates:
        Status: Closed

Comment #5 on issue 3350 by [hidden email]: Network Tests
http://code.google.com/p/pharo/issues/detail?id=3350

in 1.3 14064