betamaxteam / betamax

Betamax is a tool for mocking external HTTP resources such as web services and REST APIs in your tests. The project was inspired by the VCR library for Ruby.
http://betamax.software
Apache License 2.0
468 stars 129 forks source link

Random Port #209

Closed rmahnovetsky closed 8 years ago

rmahnovetsky commented 8 years ago

Is there a way to make betamax use a random port?

We are using feature branches and sometimes we get a port conflict on our CI server when multiple builds run at the same time. A random port will solve this issue for us.

We have tried using betamax.proxyPort=0 as this will give a random port, but the tests did not end up using the proxy

cowboygneox commented 8 years ago

First off, I very much appreciate you reporting confusion with Betamax, but since this is not currently a bug, I would ask that you use our Gitter in the future for asking questions.

Second, the issues you describe sound like they can be solved several ways. The most common way today is to use containers or VM's to run tests a process at a time, rather than having multiple processes at once, to avoid these exact issues. VM's and containerized environments, like Docker, largely mitigate these issues.

Third, if the CI environment is outside of your control, which it likely is, I would recommend that you use the ProxyConfiguration to set a port that is a mod of some range and a random number. This is something that you can configure right now.

Because port is a configurable value and the use-case of running tests on the same machine concurrently is an increasingly uncommon model, I don't see any benefit to integrating random port behavior into Betamax. Please feel free to persuade me otherwise, and let me know what you decide to go with to make your tests pass.

Thanks for using Betamax!