Make tests more robust on port collisions

- Use fewer ports overall, to make less assumptions about environment
- Anchor ports to api.port, to allow concurrent runs in IDE and command
  line
- Use teardown where appropriate to shutdown server
- Use more consistent shutdown pattern to make it visibly easier to spot
  bugs