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

zaptest: testLogSpy doesn't have to be thread-safe #567

Merged
merged 3 commits into from
Apr 9, 2018

Conversation

abhinav
Copy link
Collaborator

@abhinav abhinav commented Mar 26, 2018

This simplifies the implementation of testLogSpy by removing all
thread-safety from it. It's only used from these specific tests and
never concurrently.

@codecov
Copy link

codecov bot commented Mar 26, 2018

Codecov Report

Merging #567 into abg/test-logger will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@                 Coverage Diff                 @@
##           abg/test-logger     #567      +/-   ##
===================================================
+ Coverage            97.48%   97.49%   +0.01%     
===================================================
  Files                   40       40              
  Lines                 2026     2035       +9     
===================================================
+ Hits                  1975     1984       +9     
  Misses                  43       43              
  Partials                 8        8
Impacted Files Coverage Δ
zaptest/logger.go 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3ebc5fc...d7b6a16. Read the comment docs.

This expands the TestingT interface to a much larger subset of
`testing.TB`.

The following were left out:

- `Error` and `Log` were left out in favor of `Errorf` and `Logf`
- `Fatal*` methods were left out in favor of `Errorf` followed by
  `FailNow`
- `Skip*` methods were left out because our test logger shouldn't be
  skipping tests
- `Helper` was left out because not all supported verisons of Go have
  that
Zap's errorOutput is used exclusively to log internal errors. If this
ever gets used in a test, something catastrophic happened and we should
fail the test.

This changes the logger returned by zaptest.NewLogger to implement this
behavior by passing a `WriteSyncer` to `zap.ErrorOutput` that marks the
test as failed upon being used.

To test this, we set up a test logger and replace its core with one that
will always fail to write.
This simplifies the implementation of testLogSpy by removing all
thread-safety from it. It's only used from these specific tests and
never concurrently.
@abhinav abhinav changed the base branch from abg/test-error-output to abg/test-logger April 9, 2018 18:16
@abhinav abhinav merged commit d7b6a16 into abg/test-logger Apr 9, 2018
@abhinav abhinav deleted the abg/thread-unsafe-spy branch April 9, 2018 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants