Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
test: fix data race between multiple unit test that use envtest
Browse files Browse the repository at this point in the history
  • Loading branch information
supershal committed Apr 2, 2024
1 parent aa467be commit 18a6ab0
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions test/helpers/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ var TestEnv *TestEnvironment

// Initialize the test environment. BeforeSuite will be only executed if this package is loaded by the test.
var _ = BeforeSuite(func(ctx SpecContext) {
By("Initialize loggers for testing")
// Uninitialized logger spits stacktrace as warning during test execution
logger := textlogger.NewLogger(textlogger.NewConfig())
// use klog as the internal logger for this envtest environment.
log.SetLogger(logger)
// additionally force all of the controllers to use the Ginkgo logger.
ctrl.SetLogger(logger)
klog.InitFlags(nil)
// add logger for ginkgo
klog.SetOutput(GinkgoWriter)

By("Starting test environment")
testEnvConfig := NewTestEnvironmentConfiguration()
var err error
Expand All @@ -36,15 +47,3 @@ var _ = BeforeSuite(func(ctx SpecContext) {
var _ = AfterSuite(func(ctx context.Context) {
Expect(TestEnv.Stop()).To(Succeed())
})

//nolint:gochecknoinits //needed for test initialization
func init() {
klog.InitFlags(nil)
logger := textlogger.NewLogger(textlogger.NewConfig())
// use klog as the internal logger for this envtest environment.
log.SetLogger(logger)
// additionally force all of the controllers to use the Ginkgo logger.
ctrl.SetLogger(logger)
// add logger for ginkgo
klog.SetOutput(GinkgoWriter)
}

0 comments on commit 18a6ab0

Please sign in to comment.