-
Notifications
You must be signed in to change notification settings - Fork 4.5k
grpctest: minor improvements to the test logger implementation #8370
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: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8370 +/- ##
==========================================
- Coverage 82.44% 82.41% -0.04%
==========================================
Files 413 413
Lines 40424 40432 +8
==========================================
- Hits 33328 33321 -7
- Misses 5742 5754 +12
- Partials 1354 1357 +3
🚀 New features to boost your workflow:
|
internal/grpctest/tlogger.go
Outdated
// expected errors are declared in tests. | ||
var TLogger *tLogger | ||
var tLoggerAtomic atomic.Value |
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.
@easwars, the logger is mutated only once, in the init()
function of this package. The race usually happens in the Update
method (e.g: b/416700146#comment4) when it calls grpclog.SetLoggerV2:
Lines 35 to 41 in 6dfe07c
func SetLoggerV2(l LoggerV2) { | |
if _, ok := l.(*componentData); ok { | |
panic("cannot use component logger as grpclog logger") | |
} | |
internal.LoggerV2Impl = l | |
internal.DepthLoggerV2Impl, _ = l.(internal.DepthLoggerV2) | |
} |
Ideally
Update
should be called serially at the beginning of a test function. I've seen race conditions reported when a test doesn't wait for its goroutines to return before the test function exits. Using an atomic for LoggerV2Impl
and DepthLoggerV2Impl
might hide those errors and make it appear as though the next test has logged something. Do you think we should really change this to use an atomic?
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.
Talked to @easwars and he mentioned that we can revert the changes to make the logger an atomic.
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.
LGTM, pending the removal of the atomic. Over to Easwar for the second review.
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.
LGTM, modulo minor nits
internal/grpctest/tlogger.go
Outdated
func getLogger() *tLogger { | ||
return tLogr | ||
} |
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.
Do we really need this function?
internal/grpctest/tlogger.go
Outdated
tLogr = &tLogger{errors: map[*regexp.Regexp]int{}} | ||
vLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") | ||
if vl, err := strconv.Atoi(vLevel); err == nil { | ||
TLogger.v = vl | ||
tLogr.v = vl | ||
} |
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.
While you are here, you could reorder this such that we read the env var first, and then initialize the tLogger
. That way, you could directly set the v
field using the literal struct initialization syntax.
Also, you could use os.LookupEnv
instead of os.GetEnv
to distinguish between an empty value and an unset value.
internal/grpctest/grpctest.go
Outdated
@@ -53,7 +53,7 @@ type Tester struct{} | |||
|
|||
// Setup updates the tlogger. | |||
func (Tester) Setup(t *testing.T) { | |||
TLogger.Update(t) | |||
tLogr.Update(t) |
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.
While you are here, could we unexport the Update
and EndTest
methods on tLogger
?
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.
LGTM, modulo minor nits
vLevel = val | ||
} else { | ||
// Log the error if the environment variable is not a valid integer. | ||
fmt.Printf("Warning: GRPC_GO_LOG_VERBOSITY_LEVEL environment variable '%s' is not a valid integer. "+ |
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.
@arjan-bal is it fine if we print this message?
Fixes: #7475
Unexport the test logger implementation which is currently a package global here:
grpc-go/internal/grpctest/tlogger.go
Make the above package global accessed atomically from tests. We have had test failures because of data races in the past because of this.
Change receiver names in method of the tLogger type to be tl instead of g
RELEASE NOTES: N/A