Skip to content
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

Merged
merged 3 commits into from
Feb 17, 2021
Merged

Use a test-logger in tests rather than stdout #3976

merged 3 commits into from
Feb 17, 2021

Conversation

Groxx
Copy link
Member

@Groxx Groxx commented Feb 10, 2021

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 before suite.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.

@coveralls
Copy link

coveralls commented Feb 10, 2021

Coverage Status

Coverage increased (+0.06%) to 64.649% when pulling f31b7cb on logs into 7882518 on master.

@@ -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 {
Copy link
Contributor

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()))
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

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.
@meiliang86 meiliang86 merged commit c5334af into master Feb 17, 2021
@meiliang86 meiliang86 deleted the logs branch February 17, 2021 21:33
yux0 pushed a commit to yux0/cadence that referenced this pull request May 4, 2021
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.
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.

3 participants