use random port for tests

if port 9999 is in use the tests will fail because the port is hardcoded
I have added a try/catch with Random. It fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=755320
it'd be wise to raise the original exception instead of creating another (which obscures the backtrace).

~~~ ruby
begin
  # ...
rescue Errno::EADDRINUSE
  tries -= 1
  retry if tries > 0

  raise
end
~~~