Dear RStudio Community,
In our CI pipeline we currently test that an API (built with plumber) can be succesfully run in a sub process and run the tests defined by the developer. We follow the same framework as in plumbpkg: plumbpkg/tests/testthat/test-plumber.R at main · sol-eng/plumbpkg · GitHub
My question is how can we set the port dynamically? One needs first to make sure that the port on the server running the CI tests is available and then use the same value in the tests. How can this be achieved?
Pseudo-code here:
while port_number is not available
port_number <- port_number+1, continuethestthat::setup
run api in a background process on port <- port_numberthestthat runs tests pointing at localhost:port_number/endpoints
testthat::teardown
kill background process
Alternatively, can the port be found automatically by plumber and then passed onto a global object for the tests to use? Running plumber::plumb$run on RStudio Server Pro uses a random available port.
Best regards,
Alessandro Pirrotta