fix: Avoid race conditions
When using sync.WaitGroup, the calls to .Add should always be done before spawning the goroutine(s) we want to wait on, in the same goroutine that calls Wait. This ensures that the Add call happens before the Wait call, regardless of scheduling.
Also workaround another race in the api TestRun test, where we may need to give the server some time to start before the client can connect to it. Without the retry logic, the test seems flaky.