-
Notifications
You must be signed in to change notification settings - Fork 5
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
Automatic TearDown on Setup errors #18
Conversation
79207a2
to
9ac3a93
Compare
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 updates. It's more in line with the way I typically prefer to do things where any type of setup is either successful or it fails and cleans everything up itself so nothing is left in a half-initialized state.
|
||
// There should be only 2 goroutines live. | ||
prof := pprof.Lookup("goroutine") | ||
gotCount, wantCount := prof.Count(), 2 |
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.
This is a technique I've not seen before. I typically do this with channels and/or waitgroups.
I don't have any big objection to it, but this is probably fairly fragile since I suspect it relies on the semantics of the testing framework creating 2 goroutines.
Maybe it should get the count prior to calling SetUp
and then ensuring it matches that value here so it's robust against framework changes?
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.
Point taken. Updating to use before/after count of goroutines. The "2" is indeed due to how the test runtime spawns the individual test functions.
This adds an automatic TearDown() call for an rpc harness that fails to be setup, so that callers do not need to remember to do it themselves. This improves usability of the package by ensuring goroutines do not leak after either a failed SetUp() or a TearDown(). Unit tests are added that assert the correct behavior on both a successfull setup and when certain specific setup calls fail. This also fixes a goroutine leak in the internal memory wallet.
This adds a flag to the Harness to instruct it to keep the node dir after TearDown and, unless that flag is set, removes the node dir. This improves the reliability of the test harness by not leaving behind extraneous, unneeded data by default. When calling the TearDownInTest variant, if the test has already failed then the node dir is kept to ease debugging test failures.
9ac3a93
to
5399d59
Compare
Fix #9
This makes failures to run a harness'
SetUp()
function to automatically callTearDown()
to remove any leaking goroutines.Additionally, it fixes a shutdown goroutine leak in the memory wallet and adds a flag to force the harness to keep the node data intact on TearDown.