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

Add option to ignore current goroutines #49

Merged

Conversation

denis-tingaikin
Copy link
Contributor

@denis-tingaikin denis-tingaikin commented Jul 5, 2020

This allows usage specific tests in big projects that recently started to use go-leak check.

Signed-off-by: denis-tingajkin [email protected]

Motivation

#48

…ojects that recently started to use go-leak check.

Signed-off-by: denis-tingajkin <[email protected]>
@CLAassistant
Copy link

CLAassistant commented Jul 5, 2020

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Jul 5, 2020

Codecov Report

Merging #49 into master will increase coverage by 0.21%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #49      +/-   ##
==========================================
+ Coverage   95.20%   95.42%   +0.21%     
==========================================
  Files           4        4              
  Lines         146      153       +7     
==========================================
+ Hits          139      146       +7     
  Misses          4        4              
  Partials        3        3              
Impacted Files Coverage Δ
options.go 100.00% <100.00%> (ø)

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 4eaa857...3a68780. Read the comment docs.

Signed-off-by: denis-tingajkin <[email protected]>
@denis-tingaikin
Copy link
Contributor Author

@prashantv Is this patch make sense?

Copy link
Collaborator

@prashantv prashantv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution @denis-tingajkin

I think this change makes sense, and I think it's a clean and simple API that doesn't expose too much, nice work!

I have some small comments (rename the method, some additional test cases), I think it would also benefit from an example test, so users can see that it can be used in the same way with defer.

leaks_test.go Outdated
go func() {
<-done
}()
VerifyNone(t, IgnoreCurrentStacks())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a couple more test cases here:

  • Add a goroutine after IgnoreCurrentStacks and ensure that it is captured (you can use Find)
  • Ensure that if a goroutine is started before IgnoreCurrentStacks, it ends, and another goroutine is started, the other goroutine is noticed. (This should help ensure that goroutine IDs are not reused and so we won't have false negatives)

I'd suggest making them independent tests using t.Run rather than one long test as well, will be easier to understand what each test is testing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for proposed use cases, please take a look :)

options.go Outdated Show resolved Hide resolved
options.go Outdated Show resolved Hide resolved
Signed-off-by: denis-tingajkin <[email protected]>
Copy link
Collaborator

@prashantv prashantv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small suggestions to make the tests easier to read, but otherwise looks good.

leaks_test.go Show resolved Hide resolved
leaks_test.go Show resolved Hide resolved
leaks_test.go Show resolved Hide resolved
leaks_test.go Outdated Show resolved Hide resolved
leaks_test.go Show resolved Hide resolved
<-done
wg.Done()
}()
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add some whitespace to this test to separate out the different parts, and add comments on what we are trying to test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add some whitespace to this test to separate out the different parts, and add comments on what we are trying to test?

Sure, done. Please take a look :)

Copy link
Collaborator

@prashantv prashantv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one minor nit, thanks!

leaks_test.go Show resolved Hide resolved
@prashantv prashantv changed the title Add ignore current stacks option to avoid issues with tests in big pr… Add option to ignore current goroutines Jul 17, 2020
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