Skip to content

OnDemand static management policy

Jon Foss Mikalsen requested to merge joonnna/on-demand-policy into master

This MR introduces the DockertestOnDemand as a static management policy. I've encountered an annoyance in our current implementation that we have to pay the startup cost for containers each time we want to re-run tests after changing some code. We could get around this by using the External management policy, however, then we're required to start containers manually before running tests which is equally annoying.

I propose adding a new static management policy, DockertestOnDemand(I'm very much open to other name suggestions), which aims to eliminate said annoyance. The management policy would behave as follows:

  • Create/run container if it does not already exist
  • Do not remove container on test completion (only disconnect from docker network)
  • If an environment variable is set the static management policy would be switched to either External or Dockertest.

When running tests locally the container would be re-used between cargo test invocations eliminating startup costs when re-running tests multiple times, and not requiring manual startup.

The motivation to include an environment variable (DOCKERTEST_ON_DEMAND) is to facilitate running tests in a CI/CD pipeline without the need to change management policies.

My suggestion for its behavior is:

  • DOCKERTEST_ON_DEMAND=EXTERNAL, all containers with DockertestOnDemand are instead set to External
  • DOCKERTEST_ON_DEMAND=DOCKERTEST, all containers with DockertestOnDemand are instead set to Dockertest

This environment variable behavior could also be implemented by users instead and is up for debate if we should provide this. Although, writing that same check all over the place for different compositions might get tedious.

This branch currently contains a highly WIP implementation.

Looking for feedback on the feature itself and the implementation design/details.

Edited by Jon Foss Mikalsen

Merge request reports