test: optionally set common.PORT via env variable

This is a back-port of commit 17a8126 from the master branch.