Skip to content

Commit

Permalink
fix(test): fix test cleanup (#1290)
Browse files Browse the repository at this point in the history
# Description

When there's a failure in infra creation, `t.Cleanup` function is not
called because it is registered after job's `Run` method is called.

## Related Issue

If this pull request is related to any issue, please mention it here.
Additionally, make sure that the issue is assigned to you before
submitting this pull request.

## Checklist

- [ ] I have read the [contributing
documentation](https://retina.sh/docs/contributing).
- [ ] I signed and signed-off the commits (`git commit -S -s ...`). See
[this
documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)
on signing commits.
- [ ] I have correctly attributed the author(s) of the code.
- [ ] I have tested the changes locally.
- [ ] I have followed the project's style guidelines.
- [ ] I have updated the documentation, if necessary.
- [ ] I have added tests, if applicable.

## Screenshots (if applicable) or Testing Completed

Please add any relevant screenshots or GIFs to showcase the changes
made.

## Additional Notes

Add any additional notes or context about the pull request here.

---

Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more
information on how to contribute to this project.

Signed-off-by: Alex Castilio dos Santos <[email protected]>
  • Loading branch information
alexcastilio authored Jan 30, 2025
1 parent c17d5ea commit 8cb99a5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
5 changes: 3 additions & 2 deletions test/e2e/infra/azure_temp_infra_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ func CreateAzureTempK8sInfra(ctx context.Context, t *testing.T, rootDir string)

// CreateTestInfra
createTestInfra := types.NewRunner(t, jobs.CreateTestInfra(subID, rg, clusterName, location, kubeConfigFilePath, *common.CreateInfra))
createTestInfra.Run(ctx)

t.Cleanup(func() {
err := jobs.DeleteTestInfra(subID, rg, location, *common.DeleteInfra).Run()
if err != nil {
t.Logf("Failed to delete test infrastructure: %v", err)
}
})

createTestInfra.Run(ctx)

return kubeConfigFilePath
}
8 changes: 2 additions & 6 deletions test/e2e/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ func TestE2ERetina_Scale(t *testing.T) {

// CreateTestInfra
createTestInfra := types.NewRunner(t, jobs.CreateTestInfra(subID, rg, clusterName, location, common.KubeConfigFilePath(rootDir), *common.CreateInfra))
createTestInfra.Run(ctx)

t.Cleanup(func() {
_ = jobs.DeleteTestInfra(subID, rg, location, *common.DeleteInfra).Run()
})

createTestInfra.Run(ctx)

fqdn, err := azure.GetFqdnFn(subID, rg, clusterName)
require.NoError(t, err)
opt.AdditionalTelemetryProperty["clusterFqdn"] = fqdn
Expand All @@ -105,10 +105,6 @@ func TestE2ERetina_Scale(t *testing.T) {
installRetina := types.NewRunner(t, jobs.InstallRetina(common.KubeConfigFilePath(rootDir), common.RetinaChartPath(rootDir)))
installRetina.Run(ctx)

t.Cleanup(func() {
_ = jobs.UninstallRetina(common.KubeConfigFilePath(rootDir), common.RetinaChartPath(rootDir)).Run()
})

scale := types.NewRunner(t, jobs.ScaleTest(&opt))
scale.Run(ctx)
}

0 comments on commit 8cb99a5

Please sign in to comment.