-
Notifications
You must be signed in to change notification settings - Fork 805
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
Use a test-logger in tests rather than stdout #3976
Conversation
common/log/loggerimpl/logger.go
Outdated
@@ -52,11 +53,7 @@ func NewNopLogger() log.Logger { | |||
|
|||
// NewDevelopmentForTest is a helper to create new development logger in unit test | |||
func NewDevelopmentForTest(s suite.Suite) log.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.
nit: change name to NewLoggerForTest?
@@ -51,7 +52,9 @@ func TestWorkflowTestSuite(t *testing.T) { | |||
} | |||
|
|||
func (s *workflowTestSuite) SetupTest() { | |||
s.SetLogger(zaptest.NewLogger(s.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.
Any reason we are not changing the default here?
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.
I think that's the right choice, yeah. Among possibly other locations - any calls to zap.New...
in pretty much any go code anywhere are immediately suspect IMO.
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.
hm. unfortunately adding it there is somewhere between "not trivial" and "requires breaking changes". there doesn't appear to be any *testing.T
available at that point, and if I start changing code to require it, I eventually end up at public APIs.
still very much worthwhile, but tbh I think it's worth tackling separately.
ab71f97
to
2ffb303
Compare
Currently, on failure, e.g. matchingEngine_test.go tests spew out *ridiculous* amounts of text. This happens because Go cannot tell which logs are related to the failed test(s), so it does what it can: show all stdout. Unfortunately, stdout blends logs from parallel tests, and it's hard or impossible to find the ones relevant to the failure simply by reading. So: stop doing that. Zap has a `zaptest` package for this purpose. I'm not sure how many other places may need to be changed, but this helps the ones I'm looking at at the moment.
d874b23
to
f31b7cb
Compare
Currently, on failure, e.g. matchingEngine_test.go tests spew out *ridiculous* amounts of text. This happens because Go cannot tell which logs are related to the failed test(s), so it does what it can: show all stdout. Unfortunately, stdout blends logs from parallel tests, and it's hard or impossible to find the ones relevant to the failure simply by reading. So: stop doing that. Zap has a `zaptest` package for this purpose. I'm not sure how many other places may need to be changed, but this helps the ones I'm looking at at the moment.
Currently, on failure, e.g.
matchingEngine_test.go
tests spew out ridiculous amounts of text.This happens because Go cannot tell which logs are related to the failed test(s), so it does what it can: show all stdout.
Unfortunately, stdout blends logs from parallel tests (I don't believe it's even line-synchronized), and it's hard or impossible to find the ones relevant to the failure simply by reading.
So: stop doing that. Zap has a
zaptest
package for this purpose, we just have to use it.For tests using the workflow suite, there's an annoying call-order dependency that means we have to
suite.SetLogger
beforesuite.NewTestWorkflowEnvironment
or it's ignored... but that's not actually hard to deal with. I just wish we (and our users) didn't have to.I'm not sure how many other places may need to be changed, but this helps the ones I'm looking at at the moment.