-
Couldn't load subscription status.
- Fork 134
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 <nastyaar03@mail.ru>
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.
* 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 <nastyaar03@mail.ru>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2178 +/- ##
==========================================
+ Coverage 49.35% 49.40% +0.04%
==========================================
Files 244 253 +9
Lines 31009 31872 +863
==========================================
+ Hits 15306 15747 +441
- Misses 14561 14992 +431
+ Partials 1142 1133 -9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 updates @NastyaAR!
Our automated linter flagged some issues, which I've listed in the comments below.
You can run task lint to check if there are any linter issues before committing.
| t.Parallel() | ||
| logger.Initialize() | ||
|
|
||
| func TestFindClientConfigs(t *testing.T) { // Cant run in parallel because it uses global 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.
Our automated spell checker flagged this Cant ==> Can't
| t.Parallel() | ||
| logger.Initialize() | ||
|
|
||
| func TestFindClientConfigs(t *testing.T) { // Cant run in parallel because it uses global 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.
Could you add the line //nolint:paralleltest above func TestFindClientConfigs? This turns off linter warnings when we don't use parallel tests.
| } | ||
|
|
||
| core, observedLogs := observer.New(level) | ||
| logger := zap.New(core) |
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 there's an import called logger, it's not allowed as a variable name. testLogger would be a good alternative.
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