Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

gomock.WithContext: controller with a context #111

Merged
merged 2 commits into from
Oct 10, 2017

Conversation

abbot
Copy link
Contributor

@abbot abbot commented Sep 20, 2017

gomock.WithContext: controller with a context which is cancelled on Fatals.

testing.T.FailNow (and Fatal, ...) work only when called from the same
goroutine as the test. This makes using gomock with e.g. RPC server
mocks quite a challenge as the tests are likely to deadlock instead of
failing properly.

This adds a new constructor returning an additional context, which is
cancelled on any fatal failure in mock.

This provides a reasonable workaround for #110 and similar issues.

…atals.

testing.T.FailNow (and Fatal, ...) work only when called from the same
goroutine as the test. This makes using gomock with e.g. RPC server
mocks quite a challenge as the tests are likely to deadlock instead of
failing properly.

This adds a new constructor returning an additional context, which is
cancelled on any fatal failure in mock.
Otherwise integration tests are unhappy.
@jimpo
Copy link

jimpo commented Sep 22, 2017

This looks like a pretty decent solution to me. Thanks for getting a proposed fix out so quickly.

@abbot
Copy link
Contributor Author

abbot commented Sep 22, 2017

I just happened to write this workaround for my code earlier the same day. :)

@balshetzer, can you have a look? Thanks.

@balshetzer balshetzer merged commit 6e20fef into golang:master Oct 10, 2017
@abbot abbot deleted the withcontext branch October 10, 2017 19:36
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.

4 participants