-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POC: agent integration tests using test containers #322
Conversation
857a26c
to
181657c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These look very nice! I just gave them a couple of runs locally and run very fast. The network mode workaround looks pretty neat as the testContainers API supports it nicely.
RE test not working in MacOS, that's interesting, as the log seems to imply that TestContainer is attempting to connect to docker through the usual unix socket. If I recall correctly, in MacOS DOCKER_HOST
should be set to a tcp://somethingsomething
address, and TestContainers
claims to honor DOCKER_HOST
.
Perhaps it would be worth checking what is the value of DOCKER_HOST
in that machine to see if the system is misconfigured, or if that's a bug in TestContainers.
For me, that it doesn't work in MacOS in the CI is a minor issue, as we can run it only in Linux. What really worries me is that we don't find a workaround for developers trying to contribute to the project. |
I'll see if I can get my hands on an OSX laptop to see if I can reproduce the issue. |
I was able to successfully run these on a borrowed M1 MacBook Pro with Docker Desktop 4.21.1, without any additional changes ( On that machine, |
Signed-off-by: Pablo Chacin <[email protected]>
Signed-off-by: Pablo Chacin <[email protected]>
Signed-off-by: Pablo Chacin <[email protected]>
4acd929
to
fb6d1f5
Compare
Description
The agent tests usually require running the agent process and the SUT process, which is the target of the test requests. For example, for HTTP fault injection the SUT is usually
httpbin
. The agent uses iptables to redirect the traffic from the SUT to itself.The main difficulty when testing the agent was how to set an environment in which the agent could safely modify the iptables.
A Kubernetes pod seemed a reasonable option as each pod can run multiple containers sharing the same network stack. Besides, the most common deployment of the agent is as an ephemeral container in a Pod.
However, implementing the integration tests in this way created several issues:
This PR is a Proof of concept of using TestContainers for the agent integration tests. TestContainers allows spawning multiple containers with the components of the tests. It also offers a library of utilities for setting the containers and retrieving information such as the container's exposed ports.
Under the philosophy of TestContainer, the agent and the SUP should run as two independent containers. However, as explained above, the agent needs to share the network stack with the SUT in order to inject the traffic redirection rules.
The test implemented in this POC exploits a not well-documented feature in Docker that allows attaching a container to the network stack (or network namespace) of another container.
This workaround could be avoided by creating a test image that includes not only the agent but also other components such as httpbin and grpcbin, and starting them as processes in the same container. However, this approach introduces several issues, such as creating the test image and launching each component as a process inside the container.
Known issues and limitations
latest
tag for the agent's image. As explained in detail in Use the current branch's commit as the tag for Agent's integration tests #324, doing so introduces the risk of testing the version from the main branch instead of the one from the current branch. This could be solved relatively easily when testing locally, but in the CI requires adding additional steps for publishing the image with a tag that refers to the current branch.Checklist:
make lint
) and all checks pass.make test
) and all tests pass.make e2e-xxx
foragent
,disruptors
,kubernetes
orcluster
related changes)