Skip to content

test: Start the controller package's API servers once - #848

Merged
vvoytovych merged 2 commits into
mainfrom
test/one-envtest-per-package
Nov 4, 2026
Merged

vvoytovych merged 2 commits into
mainfrom
test/one-envtest-per-package

Conversation

@vvoytovych

@vvoytovych vvoytovych commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

The controller package's envtest tests started an API server for nearly every test, about 180 times, and the starts and stops took over half of the package's time (#837): 1062 s locally on main at 202bbf0a, and 1131–1170 s in the required check against its 20-minute test timeout. The package already shares two API servers, the planes, between the projection tests. Every test on the same CRDs, NSO's and the locations', now uses them: they start at first use and TestMain stops them, as kubebuilder's suite_test.go starts one environment for a package. The package now takes 155–161 s locally and 164 s in CI, against 1232 s on main, so go test takes Go's default timeout of 10 minutes again.

Changes

change file
The planes and TestMain move to the package's suite file. planes also gives each server's config suite_test.go, networkinterface_projection_test.go
startNetworkInterfaceEnv and the network service, repoint and connector lease tests use the first plane networkinterfaceclaim_controller_test.go, networkservice_controller_test.go, connectoradvertisement_repoint_test.go, connector_lease_watch_test.go
A name that a scenario takes from its test's name comes from scenarioSuffix. It cuts the name to fit and adds a number that no other scenario in the test binary holds. It replaces 16 copies of sanitizeName(strings.ToLower(t.Name())) and the repoint tests' own counter the scenario helpers and tests
A test deletes the cluster-scoped objects it writes: the cell's ServingLocation and a Location networkinterface_controller_test.go, subnet_controller_test.go
The load balancer intent test lists only its own hub namespace networkloadbalancercellintent_controller_test.go
The connector lease test's manager skips the controller name check, as the other manager tests do connector_lease_watch_test.go
go test takes Go's default timeout again. The package outgrew it, so d063dc42 raised it to 20 minutes and #845 to 25. The flag and its comments go .github/workflows/ci.yaml, Makefile

Corner cases

case what happens proof
Two tests whose names start the same Their names differ. On main the presence scenario cuts names at 48 characters, so on one server the restart tests' subtests would get the same namespace TestScenarioSuffixesAreUniqueAndFit
A test run twice in one process (-count) Its second run gets new names the same test; the package passes with -count=2
A test that delivers the cell's ServingLocation The ServingLocation is deleted after the test. One delivered ServingLocation wins over the configured location, so it would change the location of every later test on the plane the three tests that deliver one, run together
A test that fails part way Its namespaces stay, under names that no later test takes. Its cleanups still run named, not tested
A run without envtest's binaries The tests skip, as before sharedPlanes
A plane that fails to start Every test that needs it fails with the start error sync.OnceValues keeps the error

Not changed

  • The Gateway API tests keep their own servers, 10 starts. Their CRDs are different. TestEnsureDownstreamGatewayHTTPRoutesStatusFitsInstalledSchema rewrites the HTTPRoute CRD during the test, and TestDownstreamClientTrafficPolicyWithoutTheKind needs Envoy Gateway's kinds to be absent. The other eight could share a third server and save about 30 s. But the five DNS tests run a manager over the whole server, with fixed names and hostnames in default, so that is a separate change.
  • No test runs in parallel that did not before.

Test plan

Refs #837

The controller package started an envtest API server for nearly every
test, about 180 of them, and spent over half its time on their starts
and stops. The tests on NSO's and the locations CRDs now share the
package's two planes, started at first use and stopped by TestMain, as
kubebuilder's suite_test.go shares one environment.

A plane now outlives a test, so a name a scenario takes from its test's
name ends in a number no other scenario holds, also under -count, and a
test deletes the cluster-scoped objects it writes.

Refs #837
@vvoytovych vvoytovych self-assigned this Nov 3, 2026
The test timeout went to 20 minutes and then 25 because the controller
package's envtest suite outgrew Go's default of 10. With its API servers
started once, the package takes under 3 minutes in CI, so the flag and
its comments go, and a hung test binary is stopped after 10 minutes.

Refs #837
@vvoytovych
vvoytovych marked this pull request as ready for review November 3, 2026 19:56
@vvoytovych
vvoytovych requested a review from a team as a code owner November 3, 2026 19:56
@vvoytovych
vvoytovych requested a review from ecv November 3, 2026 19:56
@vvoytovych
vvoytovych merged commit db128bf into main Nov 4, 2026
11 checks passed
@vvoytovych
vvoytovych deleted the test/one-envtest-per-package branch November 4, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants