test: Improve integration test speed with persistent test infra #90
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR is an overhaul of our test setup, specifically regarding integration & e2e tests where test infrastructure is required (CH, LocalStack, RabbitMQ, etc.). This PR aims to improve the test speed as well the the resource consumption when running the full test suite.
The PR provides:
You can read more about how things work in the documentation (part of this PR). Short summary is to use
TESTINFRA=1environment variable to use the persistent test infra to speed up the test suite.Examples
Time
Here's an example time difference when running with the persistent test infra vs spawning testcontainer
vs with
TESTINFRA=1Resource
Besides improving speed, the
internal/util/testinfrapkg allows reusing spawned testcontainers for every tests instead of spawning a new testcontainer every test suite. This results in significant improvement in terms of resource consumption when running the full test suite.This is an example of what happens before this PR:
Every test suite that requires some infra will spawn its own testcontainers to perform the test. Sometimes, the CPU consumption goes all the way beyond the 800% CPU that I allocated for Docker. This specific run took over 2min and it ended up in some sort of testcontainer error. This issue will only get worse as we continue adding more tests as there's no upper bound to the number of testcontainer we may require.
With this PR, when running the full suite, we only spawn 3 testcontainers for CH, LocalStack, and RabbitMQ and reuse these for the whole test suite. Furthermore, we can also use
TESTINFRA=1flag to use the persistent containers to significantly improve test time.