Skip to content

fix(test): capture logs without replacing the global Logger - #3737

Merged
dnwe merged 2 commits into
IBM:mainfrom
official-burak:fix/test-logger-capture-race
Sep 21, 2026
Merged

dnwe merged 2 commits into
IBM:mainfrom
official-burak:fix/test-logger-capture-race

Conversation

@official-burak

@official-burak official-burak commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Sorry this showed up as a go test -race failure after a close. TestPartitionConsumerComputeBackoff was replacing the package Logger while TestConsumerExpiryTicker still had a safeAsyncClose goroutine reading it through DebugLogger.

The stuck-warning subtest now uses (*log.Logger).SetOutput, which is documented as safe for concurrent use, so leftover close logs no longer race with the capture. TestClientBackgroundMetadataUpdater had the same assignment, so I pointed that at the same helper.

Fixes #3736.

@puellanivis puellanivis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:not-bad: A pretty simple and measured solution.

Comment thread sarama_test.go Outdated
Comment on lines +26 to +35
std, ok := Logger.(*log.Logger)
if !ok {
orig := Logger
Logger = log.New(w, "", 0)
t.Cleanup(func() { Logger = orig })
return
}
prev := std.Writer()
std.SetOutput(w)
t.Cleanup(func() { std.SetOutput(prev) })

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Maybe a type switch? Then we don’t need the early return, as each type would be a separate case?

@dnwe dnwe added the chore label Sep 20, 2026
@dnwe
dnwe merged commit bb87bac into IBM:main Sep 21, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: race detector reports a race on global Logger

3 participants