-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Improve execution speed of unit tests #5029
Comments
I think solution 2 is already implemented by controller-runtime: https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/envtest/server.go#L40 |
The only issue I see with using an existing cluster is how we go about registering webhooks and whatnot. We can try to work around a quick way to spin up a local control plane with envtest by making sure we register all our webhooks and CRDs automatically when we start it up. |
/area testing |
Tested ./controllers/... test with testenv with an existing kind cluster (on Mac). Results: Setupkind create cluster
# Append to /etc/hosts
# 127.0.0.1 docker.for.mac.localhost Patch envtest/webhooks.go
Note: /etc/hosts and LocalServingHostExternalName was necessary, because the kube-apiserver running in kind on Docker for Mac could not reach the locally running webhooks otherwise. Tests (via Intellij with env var
|
1 is done 2 is still open (will implement "kind support" the next few days) |
@sbueringer: Reopened this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
User Story
As a developer I would like to have very fast local feedback loop with unit tests.
Detailed Description
In most of our test suites (probably all?) we start an entire tes tenv before starting the unit tests. This is of course necessary for some of our unit tests in the respective packages. But it’s also really painful when developing new unit tests which don’t need test env, because it still takes >10s to run those tests. Imho if somehow possible the feedback loop for something like that (i.e. running a subset of tests which don’t require test env) should be a lot faster. It would be really nice if we can find a way to improve this for local test development / execution.
In addition, it would be great if we can also speed up the unit tests which require test env.
Anything else you would like to add:
This topic was briefly discussed in Slack (https://kubernetes.slack.com/archives/C8TSNPY4T/p1627483162464600) and we came up with the following solutions:
Make it possible to skip the test env creation entirely (This is useful when only a subset of unit tests which doesn't need test env is executed, e.g. via IDE)
TestMain
funcs to skip the test env creation if e.g. theCAPI_DISABLE_TEST_ENV
environment variable is set. The env var can then be configured either on the command line or in the DIE.Make it possible to spin up test env once and then reuse it for multiple test runs (This is useful when unit tests which require a test env are executed, which is not adressed by 1.)
I think we should implement both as:
[Miscellaneous information that will assist in solving the issue.]
/kind feature
The text was updated successfully, but these errors were encountered: