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

Make mockT.Fatal halt execution #396

Merged
merged 2 commits into from
Apr 22, 2020
Merged

Make mockT.Fatal halt execution #396

merged 2 commits into from
Apr 22, 2020

Conversation

appilon
Copy link
Contributor

@appilon appilon commented Apr 20, 2020

The current mockT did not halt execution on Fatal, this led to a test failure as the SDK code expects t.Fatal to halt execution. This introduces a panic and recover to fix the unit test. Future use of the mock (if there are any) should follow the same pattern

@appilon appilon requested a review from a team April 20, 2020 20:41
@appilon appilon requested a review from paultyng April 20, 2020 23:15
@paultyng
Copy link
Contributor

paultyng commented Apr 21, 2020

Maybe instead you could add FailNow to the MockT?

@paultyng
Copy link
Contributor

You could alternatively just switch to this package: https://github.com/mitchellh/go-testing-interface

@appilon
Copy link
Contributor Author

appilon commented Apr 21, 2020

@paultyng We can switch to it in V2. This PR doesn't remove anything it fixes a bug where a mock test continues execution after t.Fatal and the test eventually nil panics (because our code expected it to end at t.Fatal). This PR just adds the return statements to patch that issue.

@appilon
Copy link
Contributor Author

appilon commented Apr 21, 2020

@paultyng would I be reimplementing FailNow() to actually call runtime.Goexit The issue is our mock doesn't make the called function exit, leading to one test running into nil panic. The return statements in this PR fix the problem also.

@paultyng
Copy link
Contributor

Yeah i guess in this context I'd say fix the mock, not change the code to be incorrect in a normal context. Additionally you could change these returns to panics, as they should not be hit in a normal situation?

@paultyng
Copy link
Contributor

You could simulate it for testing via panic/recover instead of using exit.

@appilon
Copy link
Contributor Author

appilon commented Apr 21, 2020

@paultyng fixed with recover/panic

@appilon appilon force-pushed the return-after-fatal branch from 605b666 to cdd4c2d Compare April 21, 2020 18:19
@appilon appilon mentioned this pull request Apr 21, 2020
@appilon appilon changed the title Return after fatal test Make mockT.Fatal halt execution Apr 21, 2020
@appilon
Copy link
Contributor Author

appilon commented Apr 21, 2020

Once this is cherry-picked to V2 it will fix a test bug in #357


func() {
defer func() {
recover()
Copy link
Contributor

Choose a reason for hiding this comment

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

just to sanity check here, i would ensure the recover value is "mockT.Fatal" or something and not an unrelated panic.

@appilon appilon requested a review from paultyng April 22, 2020 15:06
Copy link
Member

@kmoe kmoe left a comment

Choose a reason for hiding this comment

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

Excellent, thank you for chasing this down

@appilon appilon merged commit 6bb3dce into master Apr 22, 2020
@appilon appilon deleted the return-after-fatal branch April 22, 2020 15:30
@ghost
Copy link

ghost commented May 23, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators May 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants