clang-format

pull/16190/head
Muxi Yan 6 years ago
parent 1a9404876c
commit f0f6e03212
  1. 2
      src/objective-c/GRPCClient/GRPCCall.h
  2. 19
      src/objective-c/GRPCClient/GRPCCall.m
  3. 8
      src/objective-c/GRPCClient/GRPCCallOptions.m
  4. 6
      src/objective-c/GRPCClient/private/GRPCChannel.m
  5. 4
      src/objective-c/GRPCClient/private/GRPCChannelPool+Test.h
  6. 2
      src/objective-c/GRPCClient/private/GRPCChannelPool.h
  7. 26
      src/objective-c/GRPCClient/private/GRPCChannelPool.m
  8. 2
      src/objective-c/GRPCClient/private/GRPCWrappedCall.h
  9. 35
      src/objective-c/GRPCClient/private/GRPCWrappedCall.m
  10. 24
      src/objective-c/ProtoRPC/ProtoRPC.m
  11. 49
      src/objective-c/tests/ChannelTests/ChannelTests.m
  12. 73
      src/objective-c/tests/InteropTests.m

@ -181,7 +181,7 @@ extern NSString *const kGRPCTrailersKey;
* error descriptions. * error descriptions.
*/ */
- (void)didCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata - (void)didCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata
error:(nullable NSError *)error; error:(nullable NSError *)error;
@end @end

@ -28,6 +28,8 @@
#include <grpc/support/time.h> #include <grpc/support/time.h>
#import "GRPCCallOptions.h" #import "GRPCCallOptions.h"
#import "private/GRPCChannelPool.h"
#import "private/GRPCCompletionQueue.h"
#import "private/GRPCConnectivityMonitor.h" #import "private/GRPCConnectivityMonitor.h"
#import "private/GRPCHost.h" #import "private/GRPCHost.h"
#import "private/GRPCRequestHeaders.h" #import "private/GRPCRequestHeaders.h"
@ -35,8 +37,6 @@
#import "private/NSData+GRPC.h" #import "private/NSData+GRPC.h"
#import "private/NSDictionary+GRPC.h" #import "private/NSDictionary+GRPC.h"
#import "private/NSError+GRPC.h" #import "private/NSError+GRPC.h"
#import "private/GRPCChannelPool.h"
#import "private/GRPCCompletionQueue.h"
// At most 6 ops can be in an op batch for a client: SEND_INITIAL_METADATA, // At most 6 ops can be in an op batch for a client: SEND_INITIAL_METADATA,
// SEND_MESSAGE, SEND_CLOSE_FROM_CLIENT, RECV_INITIAL_METADATA, RECV_MESSAGE, // SEND_MESSAGE, SEND_CLOSE_FROM_CLIENT, RECV_INITIAL_METADATA, RECV_MESSAGE,
@ -259,12 +259,12 @@ const char *kCFStreamVarName = "grpc_cfstream";
} }
[copiedHandler didCloseWithTrailingMetadata:nil [copiedHandler didCloseWithTrailingMetadata:nil
error:[NSError errorWithDomain:kGRPCErrorDomain error:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeCancelled code:GRPCErrorCodeCancelled
userInfo:@{ userInfo:@{
NSLocalizedDescriptionKey : NSLocalizedDescriptionKey :
@"Canceled by app" @"Canceled by app"
}]]; }]];
}); });
} else { } else {
_handler = nil; _handler = nil;
@ -819,7 +819,8 @@ const char *kCFStreamVarName = "grpc_cfstream";
_responseWriteable = _responseWriteable =
[[GRXConcurrentWriteable alloc] initWithWriteable:writeable dispatchQueue:_responseQueue]; [[GRXConcurrentWriteable alloc] initWithWriteable:writeable dispatchQueue:_responseQueue];
GRPCPooledChannel *channel = [[GRPCChannelPool sharedInstance] channelWithHost:_host callOptions:_callOptions]; GRPCPooledChannel *channel =
[[GRPCChannelPool sharedInstance] channelWithHost:_host callOptions:_callOptions];
GRPCWrappedCall *wrappedCall = [channel wrappedCallWithPath:_path GRPCWrappedCall *wrappedCall = [channel wrappedCallWithPath:_path
completionQueue:[GRPCCompletionQueue completionQueue] completionQueue:[GRPCCompletionQueue completionQueue]
callOptions:_callOptions]; callOptions:_callOptions];

@ -233,7 +233,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) {
copyItems:YES] copyItems:YES]
PEMRootCertificates:[_PEMRootCertificates copy] PEMRootCertificates:[_PEMRootCertificates copy]
PEMPrivateKey:[_PEMPrivateKey copy] PEMPrivateKey:[_PEMPrivateKey copy]
PEMCertificateChain:[_PEMCertificateChain copy] PEMCertificateChain:[_PEMCertificateChain copy]
transportType:_transportType transportType:_transportType
hostNameOverride:[_hostNameOverride copy] hostNameOverride:[_hostNameOverride copy]
logContext:_logContext logContext:_logContext
@ -336,7 +336,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) {
additionalChannelArgs:kDefaultAdditionalChannelArgs additionalChannelArgs:kDefaultAdditionalChannelArgs
PEMRootCertificates:kDefaultPEMRootCertificates PEMRootCertificates:kDefaultPEMRootCertificates
PEMPrivateKey:kDefaultPEMPrivateKey PEMPrivateKey:kDefaultPEMPrivateKey
PEMCertificateChain:kDefaultPEMCertificateChain PEMCertificateChain:kDefaultPEMCertificateChain
transportType:kDefaultTransportType transportType:kDefaultTransportType
hostNameOverride:kDefaultHostNameOverride hostNameOverride:kDefaultHostNameOverride
logContext:kDefaultLogContext logContext:kDefaultLogContext
@ -363,7 +363,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) {
additionalChannelArgs:_additionalChannelArgs additionalChannelArgs:_additionalChannelArgs
PEMRootCertificates:_PEMRootCertificates PEMRootCertificates:_PEMRootCertificates
PEMPrivateKey:_PEMPrivateKey PEMPrivateKey:_PEMPrivateKey
PEMCertificateChain:_PEMCertificateChain PEMCertificateChain:_PEMCertificateChain
transportType:_transportType transportType:_transportType
hostNameOverride:_hostNameOverride hostNameOverride:_hostNameOverride
logContext:_logContext logContext:_logContext
@ -391,7 +391,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) {
additionalChannelArgs:[_additionalChannelArgs copy] additionalChannelArgs:[_additionalChannelArgs copy]
PEMRootCertificates:_PEMRootCertificates PEMRootCertificates:_PEMRootCertificates
PEMPrivateKey:_PEMPrivateKey PEMPrivateKey:_PEMPrivateKey
PEMCertificateChain:_PEMCertificateChain PEMCertificateChain:_PEMCertificateChain
transportType:_transportType transportType:_transportType
hostNameOverride:_hostNameOverride hostNameOverride:_hostNameOverride
logContext:_logContext logContext:_logContext

@ -57,7 +57,7 @@
#ifdef GRPC_COMPILE_WITH_CRONET #ifdef GRPC_COMPILE_WITH_CRONET
if (![GRPCCall isUsingCronet]) { if (![GRPCCall isUsingCronet]) {
#else #else
{ {
#endif #endif
NSError *error; NSError *error;
id<GRPCChannelFactory> factory = [GRPCSecureChannelFactory id<GRPCChannelFactory> factory = [GRPCSecureChannelFactory
@ -229,7 +229,9 @@
NSTimeInterval timeout = callOptions.timeout; NSTimeInterval timeout = callOptions.timeout;
NSAssert(timeout >= 0, @"Invalid timeout"); NSAssert(timeout >= 0, @"Invalid timeout");
if (timeout < 0) return NULL; if (timeout < 0) return NULL;
grpc_slice host_slice = serverAuthority ? grpc_slice_from_copied_string(serverAuthority.UTF8String) : grpc_empty_slice(); grpc_slice host_slice = serverAuthority
? grpc_slice_from_copied_string(serverAuthority.UTF8String)
: grpc_empty_slice();
grpc_slice path_slice = grpc_slice_from_copied_string(path.UTF8String); grpc_slice path_slice = grpc_slice_from_copied_string(path.UTF8String);
gpr_timespec deadline_ms = gpr_timespec deadline_ms =
timeout == 0 ? gpr_inf_future(GPR_CLOCK_REALTIME) timeout == 0 ? gpr_inf_future(GPR_CLOCK_REALTIME)

@ -25,7 +25,7 @@
* Initialize a pooled channel with non-default destroy delay for testing purpose. * Initialize a pooled channel with non-default destroy delay for testing purpose.
*/ */
- (nullable instancetype)initWithChannelConfiguration: - (nullable instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration (GRPCChannelConfiguration *)channelConfiguration
destroyDelay:(NSTimeInterval)destroyDelay; destroyDelay:(NSTimeInterval)destroyDelay;
/** /**
@ -45,5 +45,3 @@
- (nullable instancetype)initTestPool; - (nullable instancetype)initTestPool;
@end @end

@ -45,7 +45,7 @@ NS_ASSUME_NONNULL_BEGIN
* Initialize with an actual channel object \a channel and a reference to the channel pool. * Initialize with an actual channel object \a channel and a reference to the channel pool.
*/ */
- (nullable instancetype)initWithChannelConfiguration: - (nullable instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration; (GRPCChannelConfiguration *)channelConfiguration;
/** /**
* Create a GRPCWrappedCall object (grpc_call) from this channel. If channel is disconnected, get a * Create a GRPCWrappedCall object (grpc_call) from this channel. If channel is disconnected, get a

@ -21,15 +21,15 @@
#import "../internal/GRPCCallOptions+Internal.h" #import "../internal/GRPCCallOptions+Internal.h"
#import "GRPCChannel.h" #import "GRPCChannel.h"
#import "GRPCChannelFactory.h" #import "GRPCChannelFactory.h"
#import "GRPCChannelPool.h"
#import "GRPCChannelPool+Test.h" #import "GRPCChannelPool+Test.h"
#import "GRPCChannelPool.h"
#import "GRPCCompletionQueue.h"
#import "GRPCConnectivityMonitor.h" #import "GRPCConnectivityMonitor.h"
#import "GRPCCronetChannelFactory.h" #import "GRPCCronetChannelFactory.h"
#import "GRPCInsecureChannelFactory.h" #import "GRPCInsecureChannelFactory.h"
#import "GRPCSecureChannelFactory.h" #import "GRPCSecureChannelFactory.h"
#import "version.h"
#import "GRPCWrappedCall.h" #import "GRPCWrappedCall.h"
#import "GRPCCompletionQueue.h" #import "version.h"
#import <GRPCClient/GRPCCall+Cronet.h> #import <GRPCClient/GRPCCall+Cronet.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
@ -53,10 +53,12 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
} }
- (instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration { - (instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration {
return [self initWithChannelConfiguration:channelConfiguration destroyDelay:kDefaultChannelDestroyDelay]; return [self initWithChannelConfiguration:channelConfiguration
destroyDelay:kDefaultChannelDestroyDelay];
} }
- (nullable instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration - (nullable instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration
destroyDelay:(NSTimeInterval)destroyDelay { destroyDelay:(NSTimeInterval)destroyDelay {
NSAssert(channelConfiguration != nil, @"channelConfiguration cannot be empty."); NSAssert(channelConfiguration != nil, @"channelConfiguration cannot be empty.");
if (channelConfiguration == nil) { if (channelConfiguration == nil) {
@ -71,8 +73,8 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
_lastTimedDestroy = nil; _lastTimedDestroy = nil;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 || __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 || __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
if (@available(iOS 8.0, macOS 10.10, *)) { if (@available(iOS 8.0, macOS 10.10, *)) {
_timerQueue = dispatch_queue_create(NULL, _timerQueue = dispatch_queue_create(NULL, dispatch_queue_attr_make_with_qos_class(
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0)); DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0));
} else { } else {
#else #else
{ {
@ -115,9 +117,10 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
} }
_lastTimedDestroy = nil; _lastTimedDestroy = nil;
grpc_call *unmanagedCall = [_wrappedChannel unmanagedCallWithPath:path grpc_call *unmanagedCall =
completionQueue:[GRPCCompletionQueue completionQueue] [_wrappedChannel unmanagedCallWithPath:path
callOptions:callOptions]; completionQueue:[GRPCCompletionQueue completionQueue]
callOptions:callOptions];
if (unmanagedCall == NULL) { if (unmanagedCall == NULL) {
NSAssert(unmanagedCall != NULL, @"Unable to create grpc_call object"); NSAssert(unmanagedCall != NULL, @"Unable to create grpc_call object");
return nil; return nil;
@ -203,8 +206,7 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
+ (instancetype)sharedInstance { + (instancetype)sharedInstance {
dispatch_once(&gInitChannelPool, ^{ dispatch_once(&gInitChannelPool, ^{
gChannelPool = gChannelPool = [[GRPCChannelPool alloc] initPrivate];
[[GRPCChannelPool alloc] initPrivate];
NSAssert(gChannelPool != nil, @"Cannot initialize global channel pool."); NSAssert(gChannelPool != nil, @"Cannot initialize global channel pool.");
}); });
return gChannelPool; return gChannelPool;

@ -77,7 +77,7 @@
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE; + (instancetype) new NS_UNAVAILABLE;
- (instancetype)initWithUnmanagedCall:(grpc_call *)unmanagedCall - (instancetype)initWithUnmanagedCall:(grpc_call *)unmanagedCall
pooledChannel:(GRPCPooledChannel *)pooledChannel NS_DESIGNATED_INITIALIZER; pooledChannel:(GRPCPooledChannel *)pooledChannel NS_DESIGNATED_INITIALIZER;

@ -267,7 +267,7 @@
[GRPCOpBatchLog addOpBatchToLog:operations]; [GRPCOpBatchLog addOpBatchToLog:operations];
#endif #endif
@synchronized (self) { @synchronized(self) {
if (_call != NULL) { if (_call != NULL) {
size_t nops = operations.count; size_t nops = operations.count;
grpc_op *ops_array = gpr_malloc(nops * sizeof(grpc_op)); grpc_op *ops_array = gpr_malloc(nops * sizeof(grpc_op));
@ -275,19 +275,20 @@
for (GRPCOperation *operation in operations) { for (GRPCOperation *operation in operations) {
ops_array[i++] = operation.op; ops_array[i++] = operation.op;
} }
grpc_call_error error = grpc_call_start_batch(_call, ops_array, nops, (__bridge_retained void *)(^(bool success) { grpc_call_error error =
if (!success) { grpc_call_start_batch(_call, ops_array, nops, (__bridge_retained void *)(^(bool success) {
if (errorHandler) { if (!success) {
errorHandler(); if (errorHandler) {
} else { errorHandler();
return; } else {
} return;
} }
for (GRPCOperation *operation in operations) { }
[operation finish]; for (GRPCOperation *operation in operations) {
} [operation finish];
}), }
NULL); }),
NULL);
gpr_free(ops_array); gpr_free(ops_array);
NSAssert(error == GRPC_CALL_OK, @"Error starting a batch of operations: %i", error); NSAssert(error == GRPC_CALL_OK, @"Error starting a batch of operations: %i", error);
@ -296,7 +297,7 @@
} }
- (void)cancel { - (void)cancel {
@synchronized (self) { @synchronized(self) {
if (_call != NULL) { if (_call != NULL) {
grpc_call_cancel(_call, NULL); grpc_call_cancel(_call, NULL);
} }
@ -304,7 +305,7 @@
} }
- (void)channelDisconnected { - (void)channelDisconnected {
@synchronized (self) { @synchronized(self) {
if (_call != NULL) { if (_call != NULL) {
grpc_call_unref(_call); grpc_call_unref(_call);
_call = NULL; _call = NULL;
@ -313,7 +314,7 @@
} }
- (void)dealloc { - (void)dealloc {
@synchronized (self) { @synchronized(self) {
if (_call != NULL) { if (_call != NULL) {
grpc_call_unref(_call); grpc_call_unref(_call);
_call = NULL; _call = NULL;

@ -97,9 +97,12 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
responseHandler:(id<GRPCProtoResponseHandler>)handler responseHandler:(id<GRPCProtoResponseHandler>)handler
callOptions:(GRPCCallOptions *)callOptions callOptions:(GRPCCallOptions *)callOptions
responseClass:(Class)responseClass { responseClass:(Class)responseClass {
NSAssert(requestOptions.host.length != 0 && requestOptions.path.length != 0 && requestOptions.safety <= GRPCCallSafetyCacheableRequest, @"Invalid callOptions."); NSAssert(requestOptions.host.length != 0 && requestOptions.path.length != 0 &&
requestOptions.safety <= GRPCCallSafetyCacheableRequest,
@"Invalid callOptions.");
NSAssert(handler != nil, @"handler cannot be empty."); NSAssert(handler != nil, @"handler cannot be empty.");
if (requestOptions.host.length == 0 || requestOptions.path.length == 0 || requestOptions.safety > GRPCCallSafetyCacheableRequest) { if (requestOptions.host.length == 0 || requestOptions.path.length == 0 ||
requestOptions.safety > GRPCCallSafetyCacheableRequest) {
return nil; return nil;
} }
if (handler == nil) { if (handler == nil) {
@ -150,12 +153,12 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
self->_handler = nil; self->_handler = nil;
} }
[copiedHandler didCloseWithTrailingMetadata:nil [copiedHandler didCloseWithTrailingMetadata:nil
error:[NSError errorWithDomain:kGRPCErrorDomain error:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeCancelled code:GRPCErrorCodeCancelled
userInfo:@{ userInfo:@{
NSLocalizedDescriptionKey : NSLocalizedDescriptionKey :
@"Canceled by app" @"Canceled by app"
}]]; }]];
}); });
} else { } else {
_handler = nil; _handler = nil;
@ -223,8 +226,9 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
copiedHandler = self->_handler; copiedHandler = self->_handler;
self->_handler = nil; self->_handler = nil;
} }
[copiedHandler didCloseWithTrailingMetadata:nil [copiedHandler
error:ErrorForBadProto(message, _responseClass, error)]; didCloseWithTrailingMetadata:nil
error:ErrorForBadProto(message, _responseClass, error)];
}); });
[_call cancel]; [_call cancel];
_call = nil; _call = nil;

@ -20,8 +20,8 @@
#import "../../GRPCClient/GRPCCallOptions.h" #import "../../GRPCClient/GRPCCallOptions.h"
#import "../../GRPCClient/private/GRPCChannel.h" #import "../../GRPCClient/private/GRPCChannel.h"
#import "../../GRPCClient/private/GRPCChannelPool.h"
#import "../../GRPCClient/private/GRPCChannelPool+Test.h" #import "../../GRPCClient/private/GRPCChannelPool+Test.h"
#import "../../GRPCClient/private/GRPCChannelPool.h"
#import "../../GRPCClient/private/GRPCCompletionQueue.h" #import "../../GRPCClient/private/GRPCCompletionQueue.h"
#import "../../GRPCClient/private/GRPCWrappedCall.h" #import "../../GRPCClient/private/GRPCWrappedCall.h"
@ -40,13 +40,12 @@ static NSString *kDummyPath = @"/dummy/path";
- (void)testPooledChannelCreatingChannel { - (void)testPooledChannelCreatingChannel {
GRPCCallOptions *options = [[GRPCCallOptions alloc] init]; GRPCCallOptions *options = [[GRPCCallOptions alloc] init];
GRPCChannelConfiguration *config = [[GRPCChannelConfiguration alloc] initWithHost:kDummyHost GRPCChannelConfiguration *config =
callOptions:options]; [[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options];
GRPCPooledChannel *channel = [[GRPCPooledChannel alloc] initWithChannelConfiguration:config]; GRPCPooledChannel *channel = [[GRPCPooledChannel alloc] initWithChannelConfiguration:config];
GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue]; GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue];
GRPCWrappedCall *wrappedCall = [channel wrappedCallWithPath:kDummyPath GRPCWrappedCall *wrappedCall =
completionQueue:cq [channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
callOptions:options];
XCTAssertNotNil(channel.wrappedChannel); XCTAssertNotNil(channel.wrappedChannel);
(void)wrappedCall; (void)wrappedCall;
} }
@ -54,26 +53,22 @@ static NSString *kDummyPath = @"/dummy/path";
- (void)testTimedDestroyChannel { - (void)testTimedDestroyChannel {
const NSTimeInterval kDestroyDelay = 1.0; const NSTimeInterval kDestroyDelay = 1.0;
GRPCCallOptions *options = [[GRPCCallOptions alloc] init]; GRPCCallOptions *options = [[GRPCCallOptions alloc] init];
GRPCChannelConfiguration *config = [[GRPCChannelConfiguration alloc] initWithHost:kDummyHost GRPCChannelConfiguration *config =
callOptions:options]; [[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options];
GRPCPooledChannel *channel = [[GRPCPooledChannel alloc] initWithChannelConfiguration:config GRPCPooledChannel *channel =
destroyDelay:kDestroyDelay]; [[GRPCPooledChannel alloc] initWithChannelConfiguration:config destroyDelay:kDestroyDelay];
GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue]; GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue];
GRPCWrappedCall *wrappedCall; GRPCWrappedCall *wrappedCall;
GRPCChannel *wrappedChannel; GRPCChannel *wrappedChannel;
@autoreleasepool { @autoreleasepool {
wrappedCall = [channel wrappedCallWithPath:kDummyPath wrappedCall = [channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
completionQueue:cq
callOptions:options];
XCTAssertNotNil(channel.wrappedChannel); XCTAssertNotNil(channel.wrappedChannel);
// Unref and ref channel immediately; expect using the same raw channel. // Unref and ref channel immediately; expect using the same raw channel.
wrappedChannel = channel.wrappedChannel; wrappedChannel = channel.wrappedChannel;
wrappedCall = nil; wrappedCall = nil;
wrappedCall = [channel wrappedCallWithPath:kDummyPath wrappedCall = [channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
completionQueue:cq
callOptions:options];
XCTAssertEqual(channel.wrappedChannel, wrappedChannel); XCTAssertEqual(channel.wrappedChannel, wrappedChannel);
// Unref and ref channel after destroy delay; expect a new raw channel. // Unref and ref channel after destroy delay; expect a new raw channel.
@ -81,23 +76,20 @@ static NSString *kDummyPath = @"/dummy/path";
} }
sleep(kDestroyDelay + 1); sleep(kDestroyDelay + 1);
XCTAssertNil(channel.wrappedChannel); XCTAssertNil(channel.wrappedChannel);
wrappedCall = [channel wrappedCallWithPath:kDummyPath wrappedCall = [channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
completionQueue:cq
callOptions:options];
XCTAssertNotEqual(channel.wrappedChannel, wrappedChannel); XCTAssertNotEqual(channel.wrappedChannel, wrappedChannel);
} }
- (void)testDisconnect { - (void)testDisconnect {
const NSTimeInterval kDestroyDelay = 1.0; const NSTimeInterval kDestroyDelay = 1.0;
GRPCCallOptions *options = [[GRPCCallOptions alloc] init]; GRPCCallOptions *options = [[GRPCCallOptions alloc] init];
GRPCChannelConfiguration *config = [[GRPCChannelConfiguration alloc] initWithHost:kDummyHost GRPCChannelConfiguration *config =
callOptions:options]; [[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options];
GRPCPooledChannel *channel = [[GRPCPooledChannel alloc] initWithChannelConfiguration:config GRPCPooledChannel *channel =
destroyDelay:kDestroyDelay]; [[GRPCPooledChannel alloc] initWithChannelConfiguration:config destroyDelay:kDestroyDelay];
GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue]; GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue];
GRPCWrappedCall *wrappedCall = [channel wrappedCallWithPath:kDummyPath GRPCWrappedCall *wrappedCall =
completionQueue:cq [channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
callOptions:options];
XCTAssertNotNil(channel.wrappedChannel); XCTAssertNotNil(channel.wrappedChannel);
// Disconnect; expect wrapped channel to be dropped // Disconnect; expect wrapped channel to be dropped
@ -106,9 +98,8 @@ static NSString *kDummyPath = @"/dummy/path";
// Create a new call and unref the old call; confirm that destroy of the old call does not make // Create a new call and unref the old call; confirm that destroy of the old call does not make
// the channel disconnect, even after the destroy delay. // the channel disconnect, even after the destroy delay.
GRPCWrappedCall *wrappedCall2 = [channel wrappedCallWithPath:kDummyPath GRPCWrappedCall *wrappedCall2 =
completionQueue:cq [channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
callOptions:options];
XCTAssertNotNil(channel.wrappedChannel); XCTAssertNotNil(channel.wrappedChannel);
GRPCChannel *wrappedChannel = channel.wrappedChannel; GRPCChannel *wrappedChannel = channel.wrappedChannel;
wrappedCall = nil; wrappedCall = nil;

@ -249,8 +249,10 @@ BOOL isRemoteInteropTest(NSString *host) {
- (void)testLargeUnaryRPCWithV2API { - (void)testLargeUnaryRPCWithV2API {
XCTAssertNotNil([[self class] host]); XCTAssertNotNil([[self class] host]);
__weak XCTestExpectation *expectRecvMessage = [self expectationWithDescription:@"LargeUnaryWithV2API received message"]; __weak XCTestExpectation *expectRecvMessage =
__weak XCTestExpectation *expectRecvComplete = [self expectationWithDescription:@"LargeUnaryWithV2API received complete"]; [self expectationWithDescription:@"LargeUnaryWithV2API received message"];
__weak XCTestExpectation *expectRecvComplete =
[self expectationWithDescription:@"LargeUnaryWithV2API received complete"];
RMTSimpleRequest *request = [RMTSimpleRequest message]; RMTSimpleRequest *request = [RMTSimpleRequest message];
request.responseType = RMTPayloadType_Compressable; request.responseType = RMTPayloadType_Compressable;
@ -263,24 +265,26 @@ BOOL isRemoteInteropTest(NSString *host) {
options.hostNameOverride = [[self class] hostNameOverride]; options.hostNameOverride = [[self class] hostNameOverride];
GRPCUnaryProtoCall *call = [_service GRPCUnaryProtoCall *call = [_service
unaryCallWithMessage:request unaryCallWithMessage:request
responseHandler:[[InteropTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil responseHandler:[[InteropTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil
messageCallback:^(id message) { messageCallback:^(id message) {
XCTAssertNotNil(message); XCTAssertNotNil(message);
if (message) { if (message) {
RMTSimpleResponse *expectedResponse = [RMTSimpleResponse message]; RMTSimpleResponse *expectedResponse =
expectedResponse.payload.type = RMTPayloadType_Compressable; [RMTSimpleResponse message];
expectedResponse.payload.body = [NSMutableData dataWithLength:314159]; expectedResponse.payload.type = RMTPayloadType_Compressable;
XCTAssertEqualObjects(message, expectedResponse); expectedResponse.payload.body =
[NSMutableData dataWithLength:314159];
[expectRecvMessage fulfill]; XCTAssertEqualObjects(message, expectedResponse);
}
} [expectRecvMessage fulfill];
closeCallback:^(NSDictionary *trailingMetadata, NSError *error) { }
XCTAssertNil(error, @"Unexpected error: %@", error); }
[expectRecvComplete fulfill]; closeCallback:^(NSDictionary *trailingMetadata, NSError *error) {
}] XCTAssertNil(error, @"Unexpected error: %@", error);
callOptions:options]; [expectRecvComplete fulfill];
}]
callOptions:options];
[call start]; [call start];
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
} }
@ -602,7 +606,8 @@ BOOL isRemoteInteropTest(NSString *host) {
- (void)testCancelAfterBeginRPCWithV2API { - (void)testCancelAfterBeginRPCWithV2API {
XCTAssertNotNil([[self class] host]); XCTAssertNotNil([[self class] host]);
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"CancelAfterBeginWithV2API"]; __weak XCTestExpectation *expectation =
[self expectationWithDescription:@"CancelAfterBeginWithV2API"];
// A buffered pipe to which we never write any value acts as a writer that just hangs. // A buffered pipe to which we never write any value acts as a writer that just hangs.
__block GRPCStreamingProtoCall *call = [_service __block GRPCStreamingProtoCall *call = [_service
@ -699,7 +704,7 @@ BOOL isRemoteInteropTest(NSString *host) {
- (void)testCancelAfterFirstRequestWithV2API { - (void)testCancelAfterFirstRequestWithV2API {
XCTAssertNotNil([[self class] host]); XCTAssertNotNil([[self class] host]);
__weak XCTestExpectation *completionExpectation = __weak XCTestExpectation *completionExpectation =
[self expectationWithDescription:@"Call completed."]; [self expectationWithDescription:@"Call completed."];
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
options.transportType = self.class.transportType; options.transportType = self.class.transportType;
@ -707,20 +712,20 @@ BOOL isRemoteInteropTest(NSString *host) {
options.hostNameOverride = [[self class] hostNameOverride]; options.hostNameOverride = [[self class] hostNameOverride];
id request = id request =
[RMTStreamingOutputCallRequest messageWithPayloadSize:@21782 requestedResponseSize:@31415]; [RMTStreamingOutputCallRequest messageWithPayloadSize:@21782 requestedResponseSize:@31415];
__block GRPCStreamingProtoCall *call = [_service __block GRPCStreamingProtoCall *call = [_service
fullDuplexCallWithResponseHandler:[[InteropTestsBlockCallbacks alloc] fullDuplexCallWithResponseHandler:[[InteropTestsBlockCallbacks alloc]
initWithInitialMetadataCallback:nil initWithInitialMetadataCallback:nil
messageCallback:^(id message) { messageCallback:^(id message) {
XCTFail(@"Received unexpected response."); XCTFail(@"Received unexpected response.");
} }
closeCallback:^(NSDictionary *trailingMetadata, closeCallback:^(NSDictionary *trailingMetadata,
NSError *error) { NSError *error) {
XCTAssertEqual(error.code, GRPC_STATUS_CANCELLED); XCTAssertEqual(error.code, GRPC_STATUS_CANCELLED);
[completionExpectation fulfill]; [completionExpectation fulfill];
}] }]
callOptions:options]; callOptions:options];
[call start]; [call start];
[call writeMessage:request]; [call writeMessage:request];
[call cancel]; [call cancel];

Loading…
Cancel
Save