Cleaned up test code so that it uses a different port range from production. Refactored port allocation testing code into a common base.