Skip to content

This week's improvements #184

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

Merged
merged 35 commits into from
Mar 17, 2018
Merged

Conversation

MrMage
Copy link
Collaborator

@MrMage MrMage commented Mar 12, 2018

As discussed via Hangouts with @timburks, I'm going to gather all my changes for this week in this PR, then have them merged at once.

Notable changes:

  • Add a script to fix the project's indentation settings. Requires the CocodaPods 'xcodeproj' gem.
  • Use the system-default zlib module instead of a vendored one.
  • Make sure that the caller gets notified of errors in client calls (and add tests for that).
  • Fix the SSL-enabled tests.
  • Several fixes to gRPCTests to make them less flaky (before, they would still flake out from time to time on my machine).
  • Make the syntax of calling send and receive homogenous across all stream-sending/receiving client and server calls.
  • Add tests to ensure that timeouts are handled as expected, both client- and server-side. I'd also like to introduce a server-enforced timeout at some point, but that has more time.
  • Make sure that the client is notified about server errors (and add tests for that).
  • In line with the above, homogenize the interface of closing server sessions and sending results. Unfortunately, that means that you now have to call e.g. session.sendAndClose(response: response, status: .ok, completion: .nil) instead of just session.sendAndClose(response), because methods in protocols can't have default arguments. If you prefer, I could add another method to the protocols for the "default" case (status OK, no completion handler) in lieu of default arguments.

FYI, the increase in lines is almost exclusively due to tests.
Also, I tried to keep the number of commits reasonable, but there is just a lot of stuff in this PR.

@MrMage MrMage force-pushed the more-improvements branch from 3c87e6b to 2f93962 Compare March 13, 2018 09:41
@SebastianThiebaud
Copy link
Contributor

Nice! I've been struggling to switch indentation settings every time I switch projects. I really hope Xcode projects could embed/store a custom indentation configuration.

@MrMage
Copy link
Collaborator Author

MrMage commented Mar 14, 2018

They can, but swift generate-xcodeproj overrides that when regenerating the project :-/

@MrMage MrMage force-pushed the more-improvements branch from ca0d255 to ee99455 Compare March 15, 2018 15:09
The expected behavior is now for the client call's completion handler to be called when the whole call is completed. You can check that completion handler's `statusCode` for the call's result. The intermediate send/receive call completion handlers will also get called with an error, but that error's status code is most likely to be `.unknown` (because send/receive calls don't receive the final status from the server).
In addition, `CallResult` now also includes the operation group's success flag, but that flag is much less important now.

This includes:
- Make most completion handlers non-throwing (their errors were for the most part discarded, anyway)
- Extract Receive-Streaming into a common protocol
- Changing many completion handler interfaces to be called with a `CallResult` instead of `Data?` and `ResultOrRPCError<ReceivedType?>` instead of `(ReceivedType, Error)`
- Not throwing on end of stream, but passing `nil` to the completion handler instead
- Making `ServerSessionUnary` always return an error when one of its calls fail
- Adding test to ensure the proper error behavior.
@MrMage MrMage force-pushed the more-improvements branch from ee99455 to ac7979d Compare March 15, 2018 15:11
MrMage added 14 commits March 15, 2018 16:27
- avoid starting the server in an asynchronous block (as that can lead to it being shut down too early)
- make sure to close bidirectional calls
- wait on _all_ `receiveMessage` calls in `handleBiDiStream`. Previously, we would not wait for the first `receiveMessage` call, which could lead to race conditions.
…ers could get called twice, as well as an unsynchronized access to `CompletionQueue.operationGroups` that should be synchronized.
…g `Call` equivalents as possible, so that only server-specific methods are left in `Handler`.
… receiving SHUTDOWN still have their completion handlers called.
…I had forgotten that sending initial metadata is required).
@MrMage MrMage force-pushed the more-improvements branch 2 times, most recently from e786079 to d25d0c5 Compare March 16, 2018 15:08
@MrMage MrMage force-pushed the more-improvements branch 2 times, most recently from 05b7633 to ad6973c Compare March 16, 2018 15:28
@MrMage MrMage force-pushed the more-improvements branch from ad6973c to 0985a47 Compare March 16, 2018 15:37
@MrMage
Copy link
Collaborator Author

MrMage commented Mar 16, 2018

This should be ready to review now. Will look into the CI failures soon.

MrMage added 3 commits March 17, 2018 12:03
…thods actually *move* the metadata (so a second call to these methods would previously always return empty metadata objects).
@MrMage MrMage force-pushed the more-improvements branch from 91d7d0e to c962004 Compare March 17, 2018 11:54
@MrMage
Copy link
Collaborator Author

MrMage commented Mar 17, 2018

Closing and re-opening to measure the effects of the dependency cache...

@MrMage MrMage closed this Mar 17, 2018
@MrMage MrMage reopened this Mar 17, 2018
@MrMage MrMage force-pushed the more-improvements branch 2 times, most recently from e0026f4 to bd29ef6 Compare March 17, 2018 12:24
…, for faster CI builds.

(Also separate the dependency resolution and main build steps into separate steps, so we can time each one individually.)
@MrMage MrMage force-pushed the more-improvements branch from bd29ef6 to 9c54d0a Compare March 17, 2018 12:28
MrMage added 2 commits March 17, 2018 14:22
We need to return status OK here, as it seems like the server might never send out the last few messages once it has been asked to send a non-OK status. Alternatively, we could send a non-OK status here, but then we would need to sleep for a few milliseconds before sending the non-OK status.
…r code.

These tests don't really test the logic of the SwiftGRPC library, but are meant as an example of how one would go about testing their own client/server code that relies on SwiftGRPC.
@MrMage MrMage force-pushed the more-improvements branch from 7516d8d to 5d32204 Compare March 17, 2018 15:11
Makefile Outdated
@@ -8,6 +8,8 @@ all:

project:
swift package generate-xcodeproj
# Optional: set the generated project's indentation settings.
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a comment here to explain how to install the gem. I think it's safe to assume people will have ruby installed, but sudo gem install xcodeproj might not be obvious to non-rubyists.

@@ -23,15 +23,15 @@ let package = Package(
.library(name: "SwiftGRPC", targets: ["SwiftGRPC"]),
],
dependencies: [
.package(url: "https://github.com/Zewo/zlib.git", from: "0.4.0"),
.package(url: "https://github.com/apple/swift-nio-zlib-support.git", from: "1.0.0"),
Copy link
Member

Choose a reason for hiding this comment

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

I'm not hugely-confident that this project won't move, but since the zewo version was deprecated, I'm ok with this.

Copy link
Member

@timburks timburks left a comment

Choose a reason for hiding this comment

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

Do we have tests that verify this now?
"Ensure that any operation groups enqueued on a completion queue after receiving SHUTDOWN still have their completion handlers called"

@timburks
Copy link
Member

Thanks for all these improvements! See a few minor comments above, but overall it looks great.

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