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

Automatic TearDown on Setup errors #18

Merged
merged 2 commits into from
Oct 18, 2023
Merged

Conversation

matheusd
Copy link
Member

Fix #9

This makes failures to run a harness' SetUp() function to automatically call TearDown() 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.

Copy link
Member

@davecgh davecgh left a 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
Copy link
Member

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?

Copy link
Member Author

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.

dcrdtest/rpc_harness.go Outdated Show resolved Hide resolved
dcrdtest/rpc_harness_test.go Outdated Show resolved Hide resolved
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.
@matheusd
Copy link
Member Author

@davecgh davecgh merged commit b164c60 into decred:master Oct 18, 2023
6 checks passed
@matheusd matheusd deleted the autoteardown branch October 18, 2023 18:31
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.

Ensure harness.Setup() errors cleanly
2 participants