Fix flaky test: using a dynamic port
(cherry picked from commit b465d67)