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

chore(grpc-mock): restructure and add mock grpc tests #1579

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

ethanoroshiba
Copy link
Contributor

Summary

Divided GRPC mock tests by component and added a few more.

Background

Some parts of the GRPC mock still weren't tested, and the crate also needed a test for the new delay capabilities.

Changes

  • Divided tests up by mock, response, and matcher.
  • Added field to HealthCheckRequest so that we could more accurately test matcher::partialpbjson.
  • Added tests for the and mock combinator, matchers not matching incorrect requests, up_to_n_times, DynamicResponse, and delay.

Testing

All tests passing.

Related Issues

closes #902
closes #1559

@ethanoroshiba ethanoroshiba marked this pull request as ready for review September 27, 2024 15:11
crates/astria-grpc-mock-test/proto/health.proto Outdated Show resolved Hide resolved
crates/astria-grpc-mock-test/tests/health/test_response.rs Outdated Show resolved Hide resolved
.await
.unwrap_err();

let rsp = client
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest doing let start = Instant::now(); just before this, and after the .await.unwrap() below, you can assert that start.elapsed() >= const delay.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same comment as above, but happy to put it in still if needed

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to not change this file because it's taken from a well known service.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted in 4b15aa0, but needed a type with more fields to adequately test message_partial_pbjson so I added a new struct MockMessage to test_utils. Let me know if this works for you!

Copy link
Member

Choose a reason for hiding this comment

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

I didn't mean for you to implement this manually (although I am sure it was a good exercise to learn about prost and manual serde impls).

What if you you copy the echo server over (from here: https://github.com/hyperium/tonic/blob/master/examples/proto/echo/echo.proto) and just generate extra code?

That way we don't have to worry about potential breakage should we ever update prost or tonic.

crates/astria-grpc-mock-test/tests/health/test_response.rs Outdated Show resolved Hide resolved
Copy link
Member

@SuperFluffy SuperFluffy left a comment

Choose a reason for hiding this comment

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

This is looking good. I would not do the manual the manual mock message - just because we might end up in a situation where we bump either of prost, tonic, or pbjson, subtly breaking the derived code.

Copy link
Member

Choose a reason for hiding this comment

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

I didn't mean for you to implement this manually (although I am sure it was a good exercise to learn about prost and manual serde impls).

What if you you copy the echo server over (from here: https://github.com/hyperium/tonic/blob/master/examples/proto/echo/echo.proto) and just generate extra code?

That way we don't have to worry about potential breakage should we ever update prost or tonic.

@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
Copy link
Member

Choose a reason for hiding this comment

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

Was this added by you or by prost?

Copy link
Contributor Author

@ethanoroshiba ethanoroshiba Oct 18, 2024

Choose a reason for hiding this comment

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

Added by prost, I think at some point I may have bumped the dep and this is a new thing that the builder does? If I remember correctly, I believe I've noticed it elsewhere as well.

@ethanoroshiba
Copy link
Contributor Author

@SuperFluffy in RE to the comment ^^above (since I can't reply directly), I'm not sure the echo server would be sufficient as is. To adequately test the partial_pbjson matcher, we need a message with at least two fields, which the echo request/response does not have. Were you meaning to copy it over and add another field?

@joroshiba
Copy link
Member

This PR is stale because it has been open 45 days with no activity. Remove stale label or this PR will be
closed in 7 days.

@SuperFluffy
Copy link
Member

SuperFluffy commented Dec 11, 2024

@SuperFluffy in RE to the comment ^^above (since I can't reply directly), I'm not sure the echo server would be sufficient as is. To adequately test the partial_pbjson matcher, we need a message with at least two fields, which the echo request/response does not have. Were you meaning to copy it over and add another field?

I didn't realize I never answered. Sorry about that.

What I meant to say was that I rather you rename the health service to something else, or introduce a new service rather than extending a "well known service" (to avoid confusion).

@joroshiba joroshiba removed the stale label Dec 12, 2024
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.

test grpc delayed responses Test grpc mock combinators
4 participants