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

grpctest: use an interface instead of reflection #6553

Merged
merged 2 commits into from
Aug 15, 2023

Conversation

dfawley
Copy link
Member

@dfawley dfawley commented Aug 15, 2023

I was originally going to try to see if I could use generics to set a context.Context field in the Tester embedded in the struct so that every test case could automatically get our default deadline (and we could even forbid context.Background() from being called from tests). But, in practice we declare test methods without receivers, e.g.:

func (s) TestFoo(t *testing.T)

So the only way to do that would require a change to:

func (s s) TestFoo(t *testing.T) {
	// access s.Ctx here
}

At which point, we might just be better off doing:

func (s) TestFoo(ctx context.Context, t *testing.T)

But regardless of any of that, I found a simple cleanup to use an interface instead of reflection to find the Setup and Teardown methods, which at one point (before we started overriding the logger) were optional.

RELEASE NOTES: n/a

@dfawley dfawley added the Type: Internal Cleanup Refactors, etc label Aug 15, 2023
@dfawley dfawley added this to the 1.58 Release milestone Aug 15, 2023
@dfawley dfawley requested a review from easwars August 15, 2023 21:14
@easwars easwars assigned dfawley and unassigned easwars Aug 15, 2023
@dfawley dfawley merged commit 7d3996f into grpc:master Aug 15, 2023
1 check passed
@dfawley dfawley deleted the testcontext branch August 15, 2023 22:10
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants