Upgrade test listens on a fixed port, which may fail with 'bind address already in use' if the port was just used to send tcp sockets. The commit makes it listen on a random available port to avoid this.
Build tags are not compatible with block comments. Also adds copyright header to a few places it was missing.