From 9dd4144d70a7d83a7347927f796dcc4689105f72 Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Wed, 16 Oct 2019 14:42:43 -0700 Subject: [PATCH] swift: add test for closing gRPC streams Adding a test to match Android (see [this comment](https://github.com/lyft/envoy-mobile/pull/472#discussion_r335070694)) to validate that gRPC streams are closed with `nil` trailers, so as to force the stream to close with a data frame per the gRPC protocol spec. Signed-off-by: Michael Rebello --- .../swift/test/GRPCStreamEmitterTests.swift | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/library/swift/test/GRPCStreamEmitterTests.swift b/library/swift/test/GRPCStreamEmitterTests.swift index 855fd802ca..11c21ed9e9 100644 --- a/library/swift/test/GRPCStreamEmitterTests.swift +++ b/library/swift/test/GRPCStreamEmitterTests.swift @@ -5,10 +5,14 @@ import XCTest private let kMessageData = Data([1, 2, 3, 4]) private final class MockEmitter: StreamEmitter { - private let onSendData: (Data) -> Void + private let onSendData: (_ data: Data) -> Void + private let onClose: ((_ trailers: [String: [String]]?) -> Void)? - init(onSendData: @escaping (Data) -> Void) { + init(onSendData: @escaping (_ data: Data) -> Void, + onClose: ((_ trailers: [String: [String]]?) -> Void)? = nil) + { self.onSendData = onSendData + self.onClose = onClose } func sendData(_ data: Data) -> StreamEmitter { @@ -20,7 +24,10 @@ private final class MockEmitter: StreamEmitter { return self } - func close(trailers: [String: [String]]?) {} + func close(trailers: [String: [String]]?) { + self.onClose?(trailers) + } + func cancel() {} } @@ -59,4 +66,12 @@ final class GRPCStreamEmitterTests: XCTestCase { grpcEmitter.sendMessage(kMessageData) XCTAssertEqual(kMessageData, sentData.subdata(in: 5..