Fixes random port testing problem

Fixes random port testing problem (#685).