Another reasonable approach if you've started the command in question and it prints its listen address, is to parse its output. Epitomised by this upcoming testscript command: github.com/rogpeppe/go-...
github.com
testscript: add waitmatch command by mvdan · Pull Request #311 · rogpeppe/go-internal
(see commit messages - please do not squash)