Skip to content

Conversation

@NastyaAR
Copy link

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

  • added InitializeTest() for creating zaptest/observer in-memory logs
  • fixed TestFindClientConfigs()

 * new function for initialize test logger

Signed-off-by: NastyaAR <nastyaar03@mail.ru>
Copy link
Member

@eleftherias eleftherias left a 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.

return unstructuredLogs
}

func InitializeTest() *observer.ObservedLogs {
Copy link
Member

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
Copy link

codecov bot commented Oct 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.40%. Comparing base (b31683a) to head (8003e32).
⚠️ Report is 71 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@eleftherias eleftherias left a 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
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants