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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5665276
Add a script to fix the project's indentation settings.
MrMage Mar 12, 2018
2f93962
Add a public initializer for `ServerSessionTestStub`, to make it actu…
MrMage Mar 12, 2018
263e66b
Use Apple's "fake" zlib package instead of Zewo's real zlib code.
MrMage Mar 14, 2018
ac7979d
Ensure that errors in client calls are always provided to the user.
MrMage Mar 15, 2018
be3fae4
Also extract streaming sending methods into a dedicated `StreamSendin…
MrMage Mar 15, 2018
cacd605
Fix the SSL-enabled tests.
MrMage Mar 15, 2018
9916aea
Consolidate a few more calls into `StreamSending`.
MrMage Mar 15, 2018
730699d
Replace a few semaphores with `call.messageQueueEmpty.wait()`.
MrMage Mar 15, 2018
4cae6e5
Fix gRPCTests:
MrMage Mar 15, 2018
17b32f5
Fix a potential race condition where operation group completion handl…
MrMage Mar 15, 2018
800cea1
Tweak the visibility of `Handler.call`.
MrMage Mar 15, 2018
b5e7c19
Avoid displaying the comment about setting the generated project's in…
MrMage Mar 16, 2018
8b8e6c8
Replace some magic numbers with more understandable constants.
MrMage Mar 16, 2018
ab21b2c
Cleanup: Replace as many methods on `Handler` with their correspondin…
MrMage Mar 16, 2018
f814a34
Formatting: Replace several occurrences of `catch (let ...)` with jus…
MrMage Mar 16, 2018
90601ab
Avoid an extra dispatch in `Call.sendWithoutBlocking`.
MrMage Mar 16, 2018
d3afc45
Ensure that any operation groups enqueued on a completion queue after…
MrMage Mar 16, 2018
c1b54e6
Fix how the server handles unknown methods (broken by me in ac7979d5,…
MrMage Mar 16, 2018
2ebe048
Add tests to ensure that server-side timeouts are handled as expected.
MrMage Mar 16, 2018
0985a47
Also add client-timeout tests and rename "ErrorHandlingTests" to "Con…
MrMage Mar 16, 2018
7ed242e
"Fix" GRPCTests again by inserting a small delay in between sends. We…
MrMage Mar 16, 2018
da52b27
Only enter the `messageQueueEmpty` dispatch group if we are certain t…
MrMage Mar 16, 2018
cf323b4
Get rid of the `callbackQueue` argument for `CompletionQueue.runToCom…
MrMage Mar 16, 2018
f6d4341
Make `Server` retain its active handlers without having to resort to …
MrMage Mar 16, 2018
da28b9a
Change the `ServerSession`s such that errors thrown during operation …
MrMage Mar 16, 2018
2313a99
Fix two compiler warnings.
MrMage Mar 17, 2018
9128b60
Make `OperationGroup` cache its `...Metadata` properties, as those me…
MrMage Mar 17, 2018
c962004
Make the test expectations on `receive` consistent across Linux and m…
MrMage Mar 17, 2018
7935aeb
Fix a minor error in the Travis build script.
MrMage Mar 17, 2018
9c54d0a
Try making Travis cache the SwiftPM dependencies and APT repositories…
MrMage Mar 17, 2018
415307e
Fix the GRPCTests again without using a sleep call:
MrMage Mar 17, 2018
e7645b4
Add sample test suites to demonstrate how one would test client/serve…
MrMage Mar 17, 2018
6af3914
Add a method to `ServerSessionClientStreaming` to return an error sta…
MrMage Mar 17, 2018
8d07183
Add a blocking variant of the `send` method to `ServerStreaming`.
MrMage Mar 17, 2018
5d32204
Add tests to verify the behavior of canceling client and server calls.
MrMage Mar 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@
project.xcworkspace
xcuserdata
.build
protoc-gen-swift
protoc-gen-swiftgrpc
/protoc-gen-swift
/protoc-gen-swiftgrpc
third_party/**
Plugin/Packages/**
Plugin/Sources/protoc-gen-swiftgrpc/templates.swift
Plugin/protoc-*
Plugin/swiftgrpc.log
Plugin/echo.*.swift
Echo
test.out
echo.pid
SwiftGRPC.xcodeproj
/Echo
/test.out
/echo.pid
/SwiftGRPC.xcodeproj
Package.resolved
2 changes: 1 addition & 1 deletion .travis-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
cd
mkdir -p local

if [ $TRAVIS_OS_NAME == "osx" ]; then
if [ "$TRAVIS_OS_NAME" == "osx" ]; then
PROTOC_URL=https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-osx-x86_64.zip
else
# Install swift
Expand Down
30 changes: 19 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ os:
- linux
- osx

cache:
apt: true
directories:
- .build/checkouts
- .build/repositories

# Use Ubuntu 14.04
dist: trusty

Expand All @@ -29,23 +35,25 @@ sudo: false
addons:
apt:
packages:
- clang-3.8
- lldb-3.8
- libicu-dev
- libtool
- libcurl4-openssl-dev
- libbsd-dev
- build-essential
- libssl-dev
- uuid-dev
- curl
- unzip
- clang-3.8
- lldb-3.8
- libicu-dev
- libtool
- libcurl4-openssl-dev
- libbsd-dev
- build-essential
- libssl-dev
- uuid-dev
- curl
- unzip

install: ./.travis-install.sh

script:
- export PATH=$HOME/local/bin:$PATH
- export LD_LIBRARY_PATH=$HOME/local/lib
- swift package -v resolve
- make all
- make test
- make test-plugin
- make test-echo
14 changes: 7 additions & 7 deletions Examples/EchoXcode/Echo/EchoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class EchoViewController: NSViewController, NSTextFieldDelegate {
do {
try callServer(address: addressField.stringValue,
host: "example.com")
} catch (let error) {
} catch {
print(error)
}
}
Expand All @@ -54,7 +54,7 @@ class EchoViewController: NSViewController, NSTextFieldDelegate {
if nowStreaming {
do {
try sendClose()
} catch (let error) {
} catch {
print(error)
}
}
Expand All @@ -66,7 +66,7 @@ class EchoViewController: NSViewController, NSTextFieldDelegate {
if nowStreaming {
do {
try sendClose()
} catch (let error) {
} catch {
print(error)
}
}
Expand All @@ -76,7 +76,7 @@ class EchoViewController: NSViewController, NSTextFieldDelegate {
if nowStreaming {
do {
try sendClose()
} catch (let error) {
} catch {
print(error)
}
}
Expand Down Expand Up @@ -151,7 +151,7 @@ class EchoViewController: NSViewController, NSTextFieldDelegate {
}
try receiveExpandMessages()
displayMessageSent(requestMessage.text)
} catch (let error) {
} catch {
self.displayMessageReceived("No message received. \(error)")
}
}
Expand All @@ -169,7 +169,7 @@ class EchoViewController: NSViewController, NSTextFieldDelegate {
}
}
try sendCollectMessage()
} catch (let error) {
} catch {
self.displayMessageReceived("No message received. \(error)")
}
} else if callSelectButton.selectedSegment == 3 {
Expand All @@ -187,7 +187,7 @@ class EchoViewController: NSViewController, NSTextFieldDelegate {
}
}
try sendUpdateMessage()
} catch (let error) {
} catch {
self.displayMessageReceived("No message received. \(error)")
}
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/Google/NaturalLanguage/Sources/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if let provider = DefaultTokenProvider(scopes: scopes) {
do {
let result = try service.annotatetext(request)
print("\(result)")
} catch (let error) {
} catch {
print("ERROR: \(error)")
}
}
Expand Down
8 changes: 4 additions & 4 deletions Examples/SimpleXcode/Simple/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ class Document: NSDocument {
}
}
}
} catch (let callError) {
Swift.print("call error \(callError)")
} catch {
Swift.print("call error \(error)")
}
self.log("------------------------------")
sleep(1)
Expand Down Expand Up @@ -241,8 +241,8 @@ class Document: NSDocument {
trailingMetadata: trailingMetadataToSend)

self.log("------------------------------")
} catch (let callError) {
Swift.print("call error \(callError)")
} catch {
Swift.print("call error \(error)")
}
}

Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ all:

project:
swift package generate-xcodeproj
# Optional: set the generated project's indentation settings.
-ruby fix-indentation-settings.rb

test: all
swift test -v $(CFLAGS)
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.

.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.0.2"),
.package(url: "https://github.com/kylef/Commander.git", from: "0.8.0")
],
targets: [
.target(name: "SwiftGRPC",
dependencies: ["CgRPC", "SwiftProtobuf"]),
.target(name: "CgRPC",
dependencies: ["BoringSSL", "zlib"]),
dependencies: ["BoringSSL"]),
.target(name: "RootsEncoder"),
.target(name: "protoc-gen-swiftgrpc",
dependencies: [
Expand Down
22 changes: 11 additions & 11 deletions Sources/Examples/Echo/EchoProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,34 @@ class EchoProvider: Echo_EchoProvider {
}
}
session.waitForSendOperationsToFinish()
try session.close(withStatus: .ok, completion: nil)
}

// collect collects a sequence of messages and returns them concatenated when the caller closes.
func collect(session: Echo_EchoCollectSession) throws {
var parts: [String] = []
while true {
do {
let request = try session.receive()
guard let request = try session.receive()
else { break } // End of stream
parts.append(request.text)
} catch ServerError.endOfStream {
} catch {
print("collect error: \(error)")
break
} catch (let error) {
print("\(error)")
}
}
var response = Echo_EchoResponse()
response.text = "Swift echo collect: " + parts.joined(separator: " ")
try session.sendAndClose(response)
try session.sendAndClose(response: response, status: .ok, completion: nil)
}

// update streams back messages as they are received in an input stream.
func update(session: Echo_EchoUpdateSession) throws {
var count = 0
while true {
do {
let request = try session.receive()
guard let request = try session.receive()
else { break } // End of stream
var response = Echo_EchoResponse()
response.text = "Swift echo update (\(count)): \(request.text)"
count += 1
Expand All @@ -72,14 +74,12 @@ class EchoProvider: Echo_EchoProvider {
print("update error: \(error)")
}
}
} catch ServerError.endOfStream {
break
} catch (let error) {
print("\(error)")
} catch {
print("update error: \(error)")
break
}
}
session.waitForSendOperationsToFinish()
try session.close()
try session.close(withStatus: .ok, completion: nil)
}
}
62 changes: 42 additions & 20 deletions Sources/Examples/Echo/Generated/echo.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ fileprivate final class Echo_EchoGetCallBase: ClientCallUnaryBase<Echo_EchoReque

internal protocol Echo_EchoExpandCall: ClientCallServerStreaming {
/// Call this to wait for a result. Blocking.
func receive() throws -> Echo_EchoResponse
func receive() throws -> Echo_EchoResponse?
/// Call this to wait for a result. Nonblocking.
func receive(completion: @escaping (Echo_EchoResponse?, ClientError?) -> Void) throws
func receive(completion: @escaping (ResultOrRPCError<Echo_EchoResponse?>) -> Void) throws
}

fileprivate final class Echo_EchoExpandCallBase: ClientCallServerStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandCall {
Expand All @@ -47,13 +47,15 @@ class Echo_EchoExpandCallTestStub: ClientCallServerStreamingTestStub<Echo_EchoRe
}

internal protocol Echo_EchoCollectCall: ClientCallClientStreaming {
/// Call this to send each message in the request stream. Nonblocking.
/// Send a message to the stream. Nonblocking.
func send(_ message: Echo_EchoRequest, completion: @escaping (Error?) -> Void) throws
/// Send a message to the stream and wait for the send operation to finish. Blocking.
func send(_ message: Echo_EchoRequest) throws

/// Call this to close the connection and wait for a response. Blocking.
func closeAndReceive() throws -> Echo_EchoResponse
/// Call this to close the connection and wait for a response. Nonblocking.
func closeAndReceive(completion: @escaping (Echo_EchoResponse?, ClientError?) -> Void) throws
func closeAndReceive(completion: @escaping (ResultOrRPCError<Echo_EchoResponse>) -> Void) throws
}

fileprivate final class Echo_EchoCollectCallBase: ClientCallClientStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectCall {
Expand All @@ -68,12 +70,14 @@ class Echo_EchoCollectCallTestStub: ClientCallClientStreamingTestStub<Echo_EchoR

internal protocol Echo_EchoUpdateCall: ClientCallBidirectionalStreaming {
/// Call this to wait for a result. Blocking.
func receive() throws -> Echo_EchoResponse
func receive() throws -> Echo_EchoResponse?
/// Call this to wait for a result. Nonblocking.
func receive(completion: @escaping (Echo_EchoResponse?, ClientError?) -> Void) throws
func receive(completion: @escaping (ResultOrRPCError<Echo_EchoResponse?>) -> Void) throws

/// Call this to send each message in the request stream.
/// Send a message to the stream. Nonblocking.
func send(_ message: Echo_EchoRequest, completion: @escaping (Error?) -> Void) throws
/// Send a message to the stream and wait for the send operation to finish. Blocking.
func send(_ message: Echo_EchoRequest) throws

/// Call this to close the sending connection. Blocking.
func closeSend() throws
Expand Down Expand Up @@ -201,35 +205,53 @@ fileprivate final class Echo_EchoGetSessionBase: ServerSessionUnaryBase<Echo_Ech
class Echo_EchoGetSessionTestStub: ServerSessionUnaryTestStub, Echo_EchoGetSession {}

internal protocol Echo_EchoExpandSession: ServerSessionServerStreaming {
/// Send a message. Nonblocking.
func send(_ response: Echo_EchoResponse, completion: ((Error?) -> Void)?) throws
/// Send a message to the stream. Nonblocking.
func send(_ message: Echo_EchoResponse, completion: @escaping (Error?) -> Void) throws
/// Send a message to the stream and wait for the send operation to finish. Blocking.
func send(_ message: Echo_EchoResponse) throws

/// Close the connection and send the status. Non-blocking.
/// You MUST call this method once you are done processing the request.
func close(withStatus status: ServerStatus, completion: (() -> Void)?) throws
}

fileprivate final class Echo_EchoExpandSessionBase: ServerSessionServerStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoExpandSession {}

class Echo_EchoExpandSessionTestStub: ServerSessionServerStreamingTestStub<Echo_EchoResponse>, Echo_EchoExpandSession {}

internal protocol Echo_EchoCollectSession: ServerSessionClientStreaming {
/// Receive a message. Blocks until a message is received or the client closes the connection.
func receive() throws -> Echo_EchoRequest

/// Send a response and close the connection.
func sendAndClose(_ response: Echo_EchoResponse) throws
/// Call this to wait for a result. Blocking.
func receive() throws -> Echo_EchoRequest?
/// Call this to wait for a result. Nonblocking.
func receive(completion: @escaping (ResultOrRPCError<Echo_EchoRequest?>) -> Void) throws

/// You MUST call one of these two methods once you are done processing the request.
/// Close the connection and send a single result. Non-blocking.
func sendAndClose(response: Echo_EchoResponse, status: ServerStatus, completion: (() -> Void)?) throws
/// Close the connection and send an error. Non-blocking.
/// Use this method if you encountered an error that makes it impossible to send a response.
/// Accordingly, it does not make sense to call this method with a status of `.ok`.
func sendErrorAndClose(status: ServerStatus, completion: (() -> Void)?) throws
}

fileprivate final class Echo_EchoCollectSessionBase: ServerSessionClientStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}

class Echo_EchoCollectSessionTestStub: ServerSessionClientStreamingTestStub<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoCollectSession {}

internal protocol Echo_EchoUpdateSession: ServerSessionBidirectionalStreaming {
/// Receive a message. Blocks until a message is received or the client closes the connection.
func receive() throws -> Echo_EchoRequest
/// Call this to wait for a result. Blocking.
func receive() throws -> Echo_EchoRequest?
/// Call this to wait for a result. Nonblocking.
func receive(completion: @escaping (ResultOrRPCError<Echo_EchoRequest?>) -> Void) throws

/// Send a message. Nonblocking.
func send(_ response: Echo_EchoResponse, completion: ((Error?) -> Void)?) throws
/// Send a message to the stream. Nonblocking.
func send(_ message: Echo_EchoResponse, completion: @escaping (Error?) -> Void) throws
/// Send a message to the stream and wait for the send operation to finish. Blocking.
func send(_ message: Echo_EchoResponse) throws

/// Close a connection. Blocks until the connection is closed.
func close() throws
/// Close the connection and send the status. Non-blocking.
/// You MUST call this method once you are done processing the request.
func close(withStatus status: ServerStatus, completion: (() -> Void)?) throws
}

fileprivate final class Echo_EchoUpdateSessionBase: ServerSessionBidirectionalStreamingBase<Echo_EchoRequest, Echo_EchoResponse>, Echo_EchoUpdateSession {}
Expand Down
Loading