[bcl] Grab free ports randomly in NetworkHelpers (#5312)
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Fri, 4 Aug 2017 18:22:50 +0000 (20:22 +0200)
committerGitHub <noreply@github.com>
Fri, 4 Aug 2017 18:22:50 +0000 (20:22 +0200)
commit24c3624fee9c8fd643a9c7faba185e04f62f4993
treee799c1925b29cde28f6160d2e0d70e010b0d673b
parent2d4ea2b604554b82a555f66b2ceccecca8a8ea20
[bcl] Grab free ports randomly in NetworkHelpers (#5312)

* [bcl] Grab free ports randomly in NetworkHelpers

We're frequently seeing "address already in use" errors on Jenkins.

The theory is that when we're running tests and grab the next free
port via our custom NetworkHelpers we're getting a port which will
also be returned to a simultaneously running test (e.g. another chroot)
because we're closing the TcpListener and thus releasing the port until
we start using it in actual test code. By that time the other test
might've already opened the port, causing our test to fail.

Instead we now try to use a random port in the range 10000-60000
and try if it's available. This doesn't completely fix the inherent
race but should hopefully make it way less likely.
mcs/class/test-helpers/NetworkHelpers.cs