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

test: Avoid panics due to dereferencing a nil error #10390

Merged
merged 1 commit into from Mar 4, 2020

Conversation

jrajahalme
Copy link
Member

@jrajahalme jrajahalme commented Feb 28, 2020

Set 'CmdRes.err' to a non-nil value when command is not
successful. Also avoid calling 'Error()' on an error explicitly, so
that no panics are caused when the error is 'nil'.

This avoids test failures like this:

STEP: Deleting namespace 2020022720301k8spolicytestclusterwidepoliciestestclusterwidecon

! Panic in Spec Setup (BeforeEach) [38.899 seconds]
K8sPolicyTest
/Users/jarno/go/src/github.com/cilium/cilium/test/ginkgo-ext/scopes.go:395
Clusterwide policies
/Users/jarno/go/src/github.com/cilium/cilium/test/ginkgo-ext/scopes.go:395
Test clusterwide connectivity with policies [BeforeEach]
/Users/jarno/go/src/github.com/cilium/cilium/test/ginkgo-ext/scopes.go:430

Test Panicked
runtime error: invalid memory address or nil pointer dereference
/Users/jarno/go/src/github.com/cilium/cilium/test/ginkgo-ext/scopes.go:374

Full Stack Trace
github.com/cilium/cilium/test/ginkgo-ext.BeforeEach.func1.1(0xc000448900)
	/Users/jarno/go/src/github.com/cilium/cilium/test/ginkgo-ext/scopes.go:374 +0x5e
panic(0x26993c0, 0x3ba0bd0)
	/usr/local/Cellar/go/1.13.8/libexec/src/runtime/panic.go:679 +0x1b2
github.com/cilium/cilium/test/helpers.(*Kubectl).NamespaceDelete(0xc000384e40, 0xc000811aa0, 0x3f, 0x2)
	/Users/jarno/go/src/github.com/cilium/cilium/test/helpers/kubectl.go:859 +0x2eb
github.com/cilium/cilium/test/k8sT.glob..func7.11.1()
	/Users/jarno/go/src/github.com/cilium/cilium/test/k8sT/Policies.go:1375 +0x5b1
github.com/cilium/cilium/test/ginkgo-ext.BeforeEach.func1()

Signed-off-by: Jarno Rajahalme jarno@covalent.io


This change is Reviewable

Set 'CmdRes.err' to a non-nil value when command is not
successful. Also avoid calling 'Error()' on an error explicitly, so
that no panics are caused when the error is 'nil'.

This avoids test failures like this:

STEP: Deleting namespace 2020022720301k8spolicytestclusterwidepoliciestestclusterwidecon

! Panic in Spec Setup (BeforeEach) [38.899 seconds]
K8sPolicyTest
/Users/jarno/go/src/github.com/cilium/cilium/test/ginkgo-ext/scopes.go:395
  Clusterwide policies
  /Users/jarno/go/src/github.com/cilium/cilium/test/ginkgo-ext/scopes.go:395
    Test clusterwide connectivity with policies [BeforeEach]
    /Users/jarno/go/src/github.com/cilium/cilium/test/ginkgo-ext/scopes.go:430

    Test Panicked
    runtime error: invalid memory address or nil pointer dereference
    /Users/jarno/go/src/github.com/cilium/cilium/test/ginkgo-ext/scopes.go:374

    Full Stack Trace
    github.com/cilium/cilium/test/ginkgo-ext.BeforeEach.func1.1(0xc000448900)
    	/Users/jarno/go/src/github.com/cilium/cilium/test/ginkgo-ext/scopes.go:374 +0x5e
    panic(0x26993c0, 0x3ba0bd0)
    	/usr/local/Cellar/go/1.13.8/libexec/src/runtime/panic.go:679 +0x1b2
    github.com/cilium/cilium/test/helpers.(*Kubectl).NamespaceDelete(0xc000384e40, 0xc000811aa0, 0x3f, 0x2)
    	/Users/jarno/go/src/github.com/cilium/cilium/test/helpers/kubectl.go:859 +0x2eb
    github.com/cilium/cilium/test/k8sT.glob..func7.11.1()
    	/Users/jarno/go/src/github.com/cilium/cilium/test/k8sT/Policies.go:1375 +0x5b1
    github.com/cilium/cilium/test/ginkgo-ext.BeforeEach.func1()

Signed-off-by: Jarno Rajahalme <jarno@covalent.io>
@jrajahalme jrajahalme added pending-review kind/bug/CI This is a bug in the testing code. release-note/minor This PR changes functionality that users may find relevant to operating Cilium. labels Feb 28, 2020
@jrajahalme jrajahalme requested a review from a team as a code owner February 28, 2020 21:57
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.7.1 Feb 28, 2020
@jrajahalme
Copy link
Member Author

test-me-please

@maintainer-s-little-helper maintainer-s-little-helper bot added this to In progress in 1.8.0 Feb 28, 2020
@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 45.548% when pulling 3a71a9d on pr/jrajahalme/test-avoid-nil-dereference into 302831a on master.

@tgraf tgraf requested a review from nebril February 29, 2020 09:23
@aanm aanm merged commit 23b165c into master Mar 4, 2020
1.8.0 automation moved this from In progress to Merged Mar 4, 2020
@aanm aanm deleted the pr/jrajahalme/test-avoid-nil-dereference branch March 4, 2020 09:51
@joestringer joestringer removed this from Needs backport from master in 1.7.1 Mar 5, 2020
@joestringer joestringer added this to Needs backport from master in 1.7.2 Mar 5, 2020
@gandro
Copy link
Member

gandro commented Mar 16, 2020

@jrajahalme and @nebril This PR is marked as needing a backport to 1.7. However, this patch does not apply to the v1.7 branch. It seems to depend on ae9619a (which was not backported).

What's the verdict? Do we need to backport the other commit first, or does this commit not need a backport.

@nebril
Copy link
Member

nebril commented Mar 18, 2020

Seems like backporting to 1.7 is not needed here.

@tklauser tklauser removed this from Needs backport from master in 1.7.2 Mar 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug/CI This is a bug in the testing code. release-note/minor This PR changes functionality that users may find relevant to operating Cilium.
Projects
No open projects
1.8.0
  
Merged
Development

Successfully merging this pull request may close these issues.

None yet

5 participants