Skip to content
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

[backport 0.7] Remove os.Exit calls from TestMain #3041

Merged

Conversation

jonathanbeber
Copy link
Contributor

What type of PR is this?

/kind bug
/kind cleanup

What this PR does / why we need it:

As described in go#34129, os.Exit() in the way we have in multiple
tests in this project make panics to fail silently. That was first
described in #3032.

Since go 1.15 the os.Exit(code) calls are not required, therefore,
let's make panics visible and just run m.Run().

Which issue(s) this PR fixes:
Fixes #3032

Special notes for your reviewer:

Checklist:

  • squashed commits

Release note:

Refactor TestMain functions across the project to stop using os.Exit swallowing errors

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. needs-priority needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Dec 17, 2021
@k8s-ci-robot
Copy link
Contributor

@jonathanbeber: This issue is currently awaiting triage.

If CAPA/CAPI contributors determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot
Copy link
Contributor

Hi @jonathanbeber. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 17, 2021
@jonathanbeber jonathanbeber changed the title Remove os.Exit calls from TestMain [backport 0.6] Remove os.Exit calls from TestMain Dec 17, 2021
@sedefsavas sedefsavas changed the title [backport 0.6] Remove os.Exit calls from TestMain [backport 0.7] Remove os.Exit calls from TestMain Dec 17, 2021
@sedefsavas
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 17, 2021
@sedefsavas sedefsavas added this to the v0.7.3 milestone Dec 17, 2021
@jonathanbeber
Copy link
Contributor Author

part of #3038

@jonathanbeber
Copy link
Contributor Author

we need #3043 to fix tests.

@@ -52,11 +51,9 @@ func TestAPIs(t *testing.T) {
}

func TestMain(m *testing.M) {
code := 0
defer func() { os.Exit(code) }()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one will consume any panic, can confirm by adding a panic in any of the tests in the package.

~/Code/cluster-api-provider-aws(release-0.7)$ git diff
diff --git bootstrap/eks/api/v1alpha3/conversion_test.go bootstrap/eks/api/v1alpha3/conversion_test.go
index 9a3025df..b5b0449c 100644
--- bootstrap/eks/api/v1alpha3/conversion_test.go
+++ bootstrap/eks/api/v1alpha3/conversion_test.go
@@ -27,6 +27,7 @@ import (
 )
 
 func TestFuzzyConversion(t *testing.T) {
+       panic("test")
        g := NewWithT(t)
        scheme := runtime.NewScheme()
        g.Expect(AddToScheme(scheme)).To(Succeed())
~/Code/cluster-api-provider-aws(release-0.7)$ go test -timeout 30s sigs.k8s.io/cluster-api-provider-aws/api/v1alpha3
ok  	sigs.k8s.io/cluster-api-provider-aws/api/v1alpha3	0.021s

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for all other cases where we have defer func() { os.Exit(code) }() or similar.

As described in [go#34129], `os.Exit()` in the way we have in multiple
tests in this project make panics to fail silently. That was first
described in kubernetes-sigs#3032.

Since go 1.15 the `os.Exit(code)` calls are not required, therefore,
let's make panics visible and just run `m.Run()`.

[go#34129]: golang/go#34129
@jonathanbeber
Copy link
Contributor Author

This seems good to go

@sedefsavas
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 21, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sedefsavas

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 21, 2021
@k8s-ci-robot k8s-ci-robot merged commit a79d123 into kubernetes-sigs:release-0.7 Dec 21, 2021
@jonathanbeber jonathanbeber deleted the backport_3306_07 branch December 21, 2021 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants