-
Notifications
You must be signed in to change notification settings - Fork 44
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
refactor: Add safety to the tests, add ability to catch stderr logs and add output path validation #552
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #552 +/- ##
===========================================
- Coverage 54.73% 54.70% -0.04%
===========================================
Files 97 97
Lines 13149 13195 +46
===========================================
+ Hits 7197 7218 +21
- Misses 5287 5306 +19
- Partials 665 671 +6
|
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.
question: How does this sove the 'file not found' errors that we saw in the logs? (I assume it does, I just cant tell how - best guess is that you are 'losing' existing entries in the register and the errors came from previously registered loggers)
It doesn't. It just makes it explicit where the file not found is from. I thought this was what you were trying to achieve with the |
That sounds very much like a bug in the test suite (these tests should never be dependent on each other). If the assertion of the |
I wonder if this PR could additionally fix #556 or if that's too "distant" for it. |
It does fix it 🙂 |
Just reporting that this PR at this point, empirically, does indeed solve #556 and gives the following test times:
|
validatedPaths[i] = validatedPaths[len(validatedPaths)-1] | ||
validatedPaths = validatedPaths[:len(validatedPaths)-1] | ||
} else { | ||
err := f.Close() |
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.
suggestion: If the paths are invalid and the file closes (that felt really odd to write - is this Close needed?), then no errors will be reported and stuff will continue as if nothing is wrong, logging only to console no? Would suggest panicing instead, or at the very least logging an error (kind of feels far more severe than an error, but fatal feels abusive) before trying to close the file.
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.
If the paths are invalid and the file closes
How will this happen?
is this Close needed
If you open a file you should close it too.
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.
How will this happen?
If the err on line 222 is nil
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.
you don't reach line 222 if the path is invalid.
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.
Ah I'm reading it backwards. The problem exists though - if you give it invalid paths then an empty collection will be returned and no errors logged - the logger will then only log to console, without any notification to anyone/thing that might be watching
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.
(3) 👍
(6) I would imagine that the code would be easier to read if validatedPaths
started off empty, and had validated values added to it, instead of initializing it with everything in it and then removing invalid items.
(7) We do not own the underlying file system, it is very possible for stuff to remove any files/paths created or validated here after this function has run.
Also, how do you think this applies here and not when someone updates the config file with a new output path?
I never suggested that it wouldn't be applicable on update. Of course it would.
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'll revisit with your suggestion.
- I think this is out of scope of this PR. If you think it's worth spending time on, do you mind opening an issue for it?
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.
- done
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 this is out of scope of this PR. If you think it's worth spending time on, do you mind opening an issue for it?
Happy with that - the code is an improvement, and we can look at making it even better later. Will create ticket which can then be prioritized/dropped later.
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.
43a6fca
to
2bce7f2
Compare
Profiling the package with Shows pprof's web UI which allows us to visualize the profiling data (here we chose CPU), like: (run the command yourself to have interactive view) I note:
|
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.
Nice! Thanks Fred for putting up with my comments here. Code looks good, and is a really nice speed boost/fix for the tests.
automatically done with `go mod tidy`
52f9993
to
3cb181e
Compare
…nd add output path validation (sourcenetwork#552) Relevant issue(s) Resolves sourcenetwork#551 Resolves sourcenetwork#550 Resolves sourcenetwork#556 Description - This PR helps to solve the issue of too many open files on some systems due to loggers being added (without clearing the old ones) with every call to getLogger. - Changes were applied to the test functions to limit panics when something goes wrong. - Added validation of log paths. - Added log pipe for test that sent logs to stderr.
Relevant issue(s)
Resolves #551
Resolves #550
Resolves #556
Description
This PR helps to solve the issue of
too many open files
on some systems due to loggers being added (without clearing the old ones) with every call togetLogger
. We change the registry type frommap[string][]Logger
tomap[string]Logger
and make the corresponding adjustment for the registry functions to work without a slice.Changes were applied to the test functions to limit panics when something goes wrong.
Added an explicit
setConfig
before the test case loop onTestLogDoesntWriteMessagesToLogGivenNoLogPath
to make it clear when usinggo test ./logging -v
that the logged errors are do to a filepath error in this test.Tasks
How has this been tested?
go test ./logging -v
Specify the platform(s) on which this was tested: