Skip to content

Commit 2b38912

Browse files
committed
test/e2e/framework: handle the case where BeforeEach was never called
Some tests under e2e/storage never end up calling the Framework#BeforeEach() prolog. Handle such cases by returning early in AfterEach() by checking a new field "beforeEachStarted". Also add a nil check for ClientSet in AfterEach().
1 parent 07b358b commit 2b38912

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/e2e/framework/framework.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ type Framework struct {
110110
// the various afterEaches
111111
afterEaches map[string]AfterEachActionFunc
112112

113+
// beforeEachStarted indicates that BeforeEach has started
114+
beforeEachStarted bool
115+
113116
// configuration for framework's client
114117
Options Options
115118

@@ -179,6 +182,8 @@ func NewFramework(baseName string, options Options, client clientset.Interface)
179182

180183
// BeforeEach gets a client and makes a namespace.
181184
func (f *Framework) BeforeEach() {
185+
f.beforeEachStarted = true
186+
182187
// The fact that we need this feels like a bug in ginkgo.
183188
// https://github.com/onsi/ginkgo/issues/222
184189
f.cleanupHandle = AddCleanupAction(f.AfterEach)
@@ -356,8 +361,20 @@ func (f *Framework) AddAfterEach(name string, fn AfterEachActionFunc) {
356361

357362
// AfterEach deletes the namespace, after reading its events.
358363
func (f *Framework) AfterEach() {
364+
// If BeforeEach never started AfterEach should be skipped.
365+
// Currently some tests under e2e/storage have this condition.
366+
if !f.beforeEachStarted {
367+
return
368+
}
369+
359370
RemoveCleanupAction(f.cleanupHandle)
360371

372+
// This should not happen. Given ClientSet is a public field a test must have updated it!
373+
// Error out early before any API calls during cleanup.
374+
if f.ClientSet == nil {
375+
Failf("The framework ClientSet must not be nil at this point")
376+
}
377+
361378
// DeleteNamespace at the very end in defer, to avoid any
362379
// expectation failures preventing deleting the namespace.
363380
defer func() {

0 commit comments

Comments
 (0)