Fix flaky test: using a dynamic port
(cherry picked from commit b465d67)
(cherry picked from commit 6dac3f8)
(cherry picked from commit 8c42c22)
(cherry picked from commit b659d60)