refactor integration tests
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 62/100
Direzione di ricerca
Start with tests/integration/suite_test.go and its TestIntegration() entrypoint, plus tests/integration/helpers.go and the testhelpers.TestCase abstraction. First goal: split TestIntegration() so individual cases run via go test -run TestName. Second: separate setup from assertions in helpers like testWorkerDeploymentCreation so failures are locatable. Done means each integration case is independently runnable and assertions live in explicitly named functions.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
There are a number of issues with the integration tests that make debugging them difficult:
- There is no way to run only one of the integration tests.
This is due to the fact that there is only one go test entrypoint for the integration tests: TestIntegration() in tests/integration/suite_test.go. This monster test method spawns sub- testing.T.Run() invocations for lots of integration tests but because of the way the integration testing framework is built, there's no way for go test tool to filter out named tests.
The ideal experience would be to be able to run a single integration test using the standard go test -run TestName command.
- Test assertions and expectations are hidden in various helper functions. These helper functions do not indicate that they assert anything at all, which makes reading an integration test and figuring out what it is actually testing a tedious exercise.
For example, take the testWorkerDeploymentCreation helper function in tests/integration/helpers.go:
// testWorkerDeploymentCreation tests the creation of a WorkerDeployment and waits for the expected status
func testWorkerDeploymentCreation(
ctx context.Context,
t *testing.T,
k8sClient client.Client,
mgr manager.Manager,
ts *temporaltest.TestServer,
tc testhelpers.TestCase,
) {
twd := tc.GetTWD()
expectedStatus := tc.GetExpectedStatus()
t.Log("Creating a Connection")
temporalConnection := &temporaliov1alpha1.Connection{
ObjectMeta: metav1.ObjectMeta{
Name: twd.Spec.WorkerOptions.ConnectionRef.Name,
Namespace: twd.Namespace,
},
Spec: temporaliov1alpha1.ConnectionSpec{
HostPort: ts.GetFrontendHostPort(),
},
}
if err := k8sClient.Create(ctx, temporalConnection); err != nil {
t.Fatalf("failed to create Connection: %v", err)
}
env := testhelpers.TestEnv{
K8sClient: k8sClient,
Mgr: mgr,
Ts: ts,
Connection: temporalConnection,
ExistingDeploymentReplicas: tc.GetExistingDeploymentReplicas(),
ExistingDeploymentImages: tc.GetExistingDeploymentImages(),
ExpectedDeploymentReplicas: tc.GetExpectedDeploymentReplicas(),
}
makePreliminaryStatusTrue(ctx, t, env, twd, tc.GetPreviouslyCurrentImages())
// verify that temporal state matches the preliminary status, to confirm that makePreliminaryStatusTrue worked
verifyTemporalStateMatchesStatusEventually(t, ctx, ts, twd, twd.Status, 30*time.Second, 5*time.Second)
// apply post-status setup function
if f := tc.GetSetupFunc(); f != nil {
f(t, ctx, tc, env)
}
// Apply any test-specific mutations to the TWD before it is created.
if f := tc.GetTWDMutatorFunc(); f != nil {
f(twd)
}
t.Log("Creating a WorkerDeployment")
if err := k8sClient.Create(ctx, twd); err != nil {
t.Fatalf("failed to create WorkerDeployment: %v", err)
}
// k8sClient.Create strips the status subresource, so the TWD starts with an empty
// status. Not guaranteed to precede the controller's first reconcile, but seeding it
// here helps test cases with pre-existing target/deprecated versions converge faster
// and avoid flaking against the eventually timeouts below.
if twd.Status.TargetVersion.BuildID != "" {
if err := k8sClient.Status().Update(ctx, twd); err != nil {
t.Fatalf("failed to pre-apply TWD status: %v", err)
}
}
// Hook: runs after TWD creation but before waiting for the target Deployment.
// Use this to assert blocking behaviour and then unblock the rollout.
if f := tc.GetPostTWDCreateFunc(); f != nil {
f(t, ctx, tc, env)
}
t.Log("Waiting for the controller to reconcile")
expectedDeploymentName := k8s.ComputeVersionedDeploymentName(twd.Name, k8s.ComputeBuildID(twd))
// only wait for and create the deployment if it is expected
if expectedStatus.TargetVersion.Status != temporaliov1alpha1.VersionStatusNotRegistered {
waitForExpectedTargetDeployment(t, twd, env, 30*time.Second)
workerStopFuncs := applyDeployment(t, ctx, k8sClient, expectedDeploymentName, twd.Namespace)
defer handleStopFuncs(workerStopFuncs)
}
if wait := tc.GetWaitTime(); wait != nil {
time.Sleep(*wait)
}
verifyWorkerDeploymentStatusEventually(t, ctx, env, twd.Name, twd.Namespace, expectedStatus, 30*time.Second, 5*time.Second)
verifyTemporalStateMatchesStatusEventually(t, ctx, ts, twd, *expectedStatus, 30*time.Second, 5*time.Second)
// apply post-expected-status validation function
if f := tc.GetValidatorFunc(); f != nil {
tc.GetValidatorFunc()(t, ctx, tc, env)
}
}
The above function is performing an awful lot of setup actions in addition to asserting a dozen or more things. It's not easy to read and when an error occurs in one of the verifyXXX functions, that error is written into the output of the integration testing framework's stdout along with the entire controller log, making it virtually impossible to spot what exactly happened.
My long-term recommendation is to migrate to a more declarative manner of running functional integration tests (using something like gdt/kube would be cool :) ). In the meantime, however, there are some concrete things we can do to make the existing integration testing framework easier to work with. First and foremost, splitting the one TestIntegration function out into many smaller testing functions would allow us to run a specific test using go test -run. Secondly, cleaning up the helper functions to decouple assertions from setup/construction would make the tests themselves easier to debug.
- Lingua principale
- Go
- Stelle
- 198
- Fork
- 84
- Merge medio
- 2g 18h
- PR unite (30g)
- 35
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di temporalio/temporal-worker-controller
-
enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
temporalio/temporal-worker-controller#692 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
documentation good first issue help wanted
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
temporalio/temporal-worker-controller#691 ·
I maintainer di solito rispondono entro 1 giorno
-
[Feature Request] Configure temporal-worker-controller to use hostNetworkForse già presa @josh-ferrell l’ha presa 9 giorni fa. Apertahelm
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
temporalio/temporal-worker-controller#680 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Feature Request] Helm chart: support topologySpreadConstraints on the controller DeploymentForse già presa @akolacz l’ha presa 17 giorni fa. Apertahelm
temporalio/temporal-worker-controller#658 · 1 reazione · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
rbac
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
temporalio/temporal-worker-controller#654 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di temporalio/temporal-worker-controller
Issue simili
-
WriterSetTimes: the UTIME_NOW check fails when the kernel uses its coarse clockForse già presa @JakeChampion l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
JakeChampion/lang#14224 ·
I maintainer di solito rispondono entro 1 giorno
-
agent-butler-finding bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
jordansmall/spindrift#6391 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
SAP/crossplane-provider-btp#1175 ·
I maintainer di solito rispondono entro 1 giorno
-
Broken links in the docsAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
adk: stream concatenation errors bypass retry and failoverForse già presa @OUAO-FRANK l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno