[squeak-dev] Re: Port numbers in network tests

Colin Putney colin at wiresong.com
Thu Apr 4 16:34:47 UTC 2013


On Thu, Apr 4, 2013 at 5:30 AM, Frank Shearar <frank.shearar at gmail.com>wrote:


> In particular, this doesn't break any tests (but haven't yet verified
> that it works for the above use case!):
>
> port
>     | freePort socket |
>     port ifNotNil: [^ port].
>     freePort := 7766.
>     socket := Socket newTCP.
>     [[socket listenOn: freePort.
>     freePort := freePort + 1.
>     socket isWaitingForConnection] whileFalse]
>         ensure: [socket destroy].
>     ^ port := freePort.
>
> where port is a new instvar that allows us to remember the free port
> we just found. Note that this only works because of TestCase's (too)
> broad remit; one TestCase instance runs one test.


I suggest trying ports randomly, rather than sequentially, as there's lower
chance of collision.

Also, TestCase's broad remit is designed for exactly this sort of
situation. It's a feature! :-)

Colin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20130404/8d1d8f94/attachment.htm


More information about the Squeak-dev mailing list