Testing socket connection.

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

Testing socket connection.

Howard Oh
How do i test if the ServerSocket accepts socket connection.
Could anyone provide some test code for me?

I use Dolphin 4 with SUnit package.

Tricky part is that I cannot block test process until connection is
astablished. If a Semaphore is used to make it wait then dolphin is
freezed.


testServantsAssigning

        "semaphore := Semaphore new.
        [server startService.
        server when: #newServant: send: #onNewServant: to: self.
        clientA connect: 'localhost'] forkHigher:5.
        semaphore wait.
        self assert: server servants size isZero not."

        "semaphore := Semaphore new."
        server startService.
        "server when: #newServant: send: #signal to: semaphore."
        clientA connect: 'localhost'.
        "semaphore wait."
        self assert: server servants size isZero not.


Reply | Threaded
Open this post in threaded view
|

Re: Testing socket connection.

Bill Dargel
Howard Oh wrote:
> Tricky part is that I cannot block test process until connection is
> astablished. If a Semaphore is used to make it wait then dolphin is
> freezed.

That's because the asynchronous implementation of Sockets that Dolphin 4
and 5 uses, requires that the main UI process be actively pumping
Window's messages in order for it to work. I think that if you simply
use ModalMsgLoop in place of a Semaphore in your test case, that the
approach you're taking should work.

--
Bill Dargel            [hidden email]
Shoshana Technologies
100 West Joy Road, Ann Arbor, MI 48105  USA


Reply | Threaded
Open this post in threaded view
|

Re: Testing socket connection.

Howard Oh
thanks, it works!!