<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 4, 2013 at 5:30 AM, Frank Shearar <span dir="ltr">&lt;<a href="mailto:frank.shearar@gmail.com" target="_blank">frank.shearar@gmail.com</a>&gt;</span> wrote:<br>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><span class="Apple-style-span" style="color:rgb(34,34,34)">In particular, this doesn&#39;t break any tests (but haven&#39;t yet verified</span><br>
</div></div>
that it works for the above use case!):<br>
<br>
port<br>
    | freePort socket |<br>
    port ifNotNil: [^ port].<br>
    freePort := 7766.<br>
    socket := Socket newTCP.<br>
    [[socket listenOn: freePort.<br>
    freePort := freePort + 1.<br>
    socket isWaitingForConnection] whileFalse]<br>
        ensure: [socket destroy].<br>
    ^ port := freePort.<br>
<br>
where port is a new instvar that allows us to remember the free port<br>
we just found. Note that this only works because of TestCase&#39;s (too)<br>
broad remit; one TestCase instance runs one test.</blockquote><div><br></div><div>I suggest trying ports randomly, rather than sequentially, as there&#39;s lower chance of collision.</div><div><br></div><div>Also, TestCase&#39;s broad remit is designed for exactly this sort of situation. It&#39;s a feature! :-)</div>
<div><br></div><div>Colin</div></div></div></div>