-
Notifications
You must be signed in to change notification settings - Fork 132
Fix flacky tests #2178
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
base: main
Are you sure you want to change the base?
Fix flacky tests #2178
Conversation
* new function for initialize test logger Signed-off-by: NastyaAR <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @NastyaAR!
The overall approach looks good, I've left a few comments inline.
pkg/logger/logger.go
Outdated
return unstructuredLogs | ||
} | ||
|
||
func InitializeTest() *observer.ObservedLogs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is only used in config_test.go
let's make it a test helper in that file.
pkg/logger/logger.go
Outdated
|
||
logger := zap.New(core) | ||
zap.ReplaceGlobals(logger) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a cleanup step here that restores the global logger
originalLogger := zap.L()
zap.ReplaceGlobals(testLogger)
t.Cleanup(func() {
zap.ReplaceGlobals(originalLogger)
})
pkg/client/config_test.go
Outdated
} | ||
|
||
func TestFindClientConfigs(t *testing.T) { | ||
t.Parallel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot run this test in parallel with others because it replaces the global logger. If multiple tests do this, it's not clear which logger will be used.
* transfer init test logger function from logger to config_test, make it helper * add cleanup with restoring original logger * make test sequential Signed-off-by: NastyaAR <[email protected]>
This problem occured due to parallel reading of os.Stderr (logger.Initialize ->logger.InitializeWithEnv -> zap.Config.Build) and writing to it when intercepting stderr in TestFindClientConfigs.
Changes