From 175580aedc5d6d72431b777a2c801f52baf6e428 Mon Sep 17 00:00:00 2001 From: "Denny C. Dai" Date: Wed, 1 Jun 2022 16:35:47 -0700 Subject: [PATCH] [gRPC/iOS] Moving remote interop test from to interop test suite (#29808) --- .../Common/GRPCBlockCallbackResponseHandler.h | 34 ++++ .../Common/GRPCBlockCallbackResponseHandler.m | 78 ++++++++ .../tests/InteropTests/InteropTestsRemote.m | 149 ++++++++++++++ src/objective-c/tests/UnitTests/APIv2Tests.m | 186 ++++-------------- .../tests/UnitTests/GRPCClientTests.m | 72 ------- 5 files changed, 296 insertions(+), 223 deletions(-) create mode 100644 src/objective-c/tests/Common/GRPCBlockCallbackResponseHandler.h create mode 100644 src/objective-c/tests/Common/GRPCBlockCallbackResponseHandler.m diff --git a/src/objective-c/tests/Common/GRPCBlockCallbackResponseHandler.h b/src/objective-c/tests/Common/GRPCBlockCallbackResponseHandler.h new file mode 100644 index 00000000000..3a39ab0c7cf --- /dev/null +++ b/src/objective-c/tests/Common/GRPCBlockCallbackResponseHandler.h @@ -0,0 +1,34 @@ +/* + * + * Copyright 2019 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#import +#import + +// Convenience class to use blocks as callbacks +@interface GRPCBlockCallbackResponseHandler : NSObject + +- (instancetype)initWithInitialMetadataCallback:(void (^)(NSDictionary *))initialMetadataCallback + messageCallback:(void (^)(id))messageCallback + closeCallback:(void (^)(NSDictionary *, NSError *))closeCallback + writeDataCallback:(void (^)(void))writeDataCallback; + +- (instancetype)initWithInitialMetadataCallback:(void (^)(NSDictionary *))initialMetadataCallback + messageCallback:(void (^)(id))messageCallback + closeCallback:(void (^)(NSDictionary *, NSError *))closeCallback; + +@end diff --git a/src/objective-c/tests/Common/GRPCBlockCallbackResponseHandler.m b/src/objective-c/tests/Common/GRPCBlockCallbackResponseHandler.m new file mode 100644 index 00000000000..c797b0e91bc --- /dev/null +++ b/src/objective-c/tests/Common/GRPCBlockCallbackResponseHandler.m @@ -0,0 +1,78 @@ +/** + * Copyright 2022 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "GRPCBlockCallbackResponseHandler.h" + +@implementation GRPCBlockCallbackResponseHandler { + void (^_initialMetadataCallback)(NSDictionary *); + void (^_messageCallback)(id); + void (^_closeCallback)(NSDictionary *, NSError *); + void (^_writeDataCallback)(void); + dispatch_queue_t _dispatchQueue; +} + +- (instancetype)initWithInitialMetadataCallback:(void (^)(NSDictionary *))initialMetadataCallback + messageCallback:(void (^)(id))messageCallback + closeCallback:(void (^)(NSDictionary *, NSError *))closeCallback + writeDataCallback:(void (^)(void))writeDataCallback { + if ((self = [super init])) { + _initialMetadataCallback = initialMetadataCallback; + _messageCallback = messageCallback; + _closeCallback = closeCallback; + _writeDataCallback = writeDataCallback; + _dispatchQueue = dispatch_queue_create(nil, DISPATCH_QUEUE_SERIAL); + } + return self; +} + +- (instancetype)initWithInitialMetadataCallback:(void (^)(NSDictionary *))initialMetadataCallback + messageCallback:(void (^)(id))messageCallback + closeCallback:(void (^)(NSDictionary *, NSError *))closeCallback { + return [self initWithInitialMetadataCallback:initialMetadataCallback + messageCallback:messageCallback + closeCallback:closeCallback + writeDataCallback:nil]; +} + +- (void)didReceiveInitialMetadata:(NSDictionary *)initialMetadata { + if (self->_initialMetadataCallback) { + self->_initialMetadataCallback(initialMetadata); + } +} + +- (void)didReceiveRawMessage:(id)message { + if (self->_messageCallback) { + self->_messageCallback(message); + } +} + +- (void)didCloseWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error { + if (self->_closeCallback) { + self->_closeCallback(trailingMetadata, error); + } +} + +- (void)didWriteData { + if (self->_writeDataCallback) { + self->_writeDataCallback(); + } +} + +- (dispatch_queue_t)dispatchQueue { + return _dispatchQueue; +} + +@end diff --git a/src/objective-c/tests/InteropTests/InteropTestsRemote.m b/src/objective-c/tests/InteropTests/InteropTestsRemote.m index 6f9cca10e7e..e1f600d0ff0 100644 --- a/src/objective-c/tests/InteropTests/InteropTestsRemote.m +++ b/src/objective-c/tests/InteropTests/InteropTestsRemote.m @@ -17,10 +17,22 @@ */ #import +#import #import +#import + +#import "../Common/GRPCBlockCallbackResponseHandler.h" + +#import "src/objective-c/tests/RemoteTestClient/Messages.pbobjc.h" +#import "src/objective-c/tests/RemoteTestClient/Test.pbobjc.h" +#import "src/objective-c/tests/RemoteTestClient/Test.pbrpc.h" #import "InteropTests.h" +// Package and service name of test server +static NSString *const kPackage = @"grpc.testing"; +static NSString *const kService = @"TestService"; + // The server address is derived from preprocessor macro, which is // in turn derived from environment variable of the same name. #define NSStringize_helper(x) #x @@ -31,12 +43,18 @@ static NSString *const kRemoteSSLHost = NSStringize(HOST_PORT_REMOTE); // by experiment. Adjust this when server's proto file changes. static int32_t kRemoteInteropServerOverhead = 12; +static const NSTimeInterval kTestTimeout = 8; + +static GRPCProtoMethod *kUnaryCallMethod; + /** Tests in InteropTests.m, sending the RPCs to a remote SSL server. */ @interface InteropTestsRemote : InteropTests @end @implementation InteropTestsRemote +#pragma mark - InteropTests + + (NSString *)host { return kRemoteSSLHost; } @@ -61,4 +79,135 @@ static int32_t kRemoteInteropServerOverhead = 12; return YES; } +#pragma mark - InteropTestsRemote tests + +- (void)setUp { + [super setUp]; + + kUnaryCallMethod = [[GRPCProtoMethod alloc] initWithPackage:kPackage + service:kService + method:@"UnaryCall"]; +} + +- (void)testMetadataForV2Call { + XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."]; + + RMTSimpleRequest *request = [RMTSimpleRequest message]; + request.fillUsername = YES; + request.fillOauthScope = YES; + + GRPCRequestOptions *callRequest = + [[GRPCRequestOptions alloc] initWithHost:[[self class] host] + path:kUnaryCallMethod.HTTPPath + safety:GRPCCallSafetyDefault]; + __block NSDictionary *init_md; + __block NSDictionary *trailing_md; + GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; + options.oauth2AccessToken = @"bogusToken"; + + GRPCCall2 *call = [[GRPCCall2 alloc] + initWithRequestOptions:callRequest + responseHandler:[[GRPCBlockCallbackResponseHandler alloc] + initWithInitialMetadataCallback:^(NSDictionary *initialMetadata) { + init_md = initialMetadata; + } + messageCallback:^(id message) { + XCTFail(@"Received unexpected response."); + } + closeCallback:^(NSDictionary *trailingMetadata, NSError *error) { + trailing_md = trailingMetadata; + if (error) { + XCTAssertEqual(error.code, 16, + @"Finished with unexpected error: %@", error); + XCTAssertEqualObjects(init_md, + error.userInfo[kGRPCHeadersKey]); + XCTAssertEqualObjects(trailing_md, + error.userInfo[kGRPCTrailersKey]); + NSString *challengeHeader = init_md[@"www-authenticate"]; + XCTAssertGreaterThan(challengeHeader.length, 0, + @"No challenge in response headers %@", + init_md); + [expectation fulfill]; + } + }] + callOptions:options]; + + [call start]; + [call writeData:[request data]]; + [call finish]; + + [self waitForExpectationsWithTimeout:kTestTimeout handler:nil]; +} + +- (void)testMetadataForV1Call { + XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."]; + + RMTSimpleRequest *request = [RMTSimpleRequest message]; + request.fillUsername = YES; + request.fillOauthScope = YES; + GRXWriter *requestsWriter = [GRXWriter writerWithValue:[request data]]; + + GRPCCall *call = [[GRPCCall alloc] initWithHost:kRemoteSSLHost + path:kUnaryCallMethod.HTTPPath + requestsWriter:requestsWriter]; + + call.oauth2AccessToken = @"bogusToken"; + + id responsesWriteable = [[GRXWriteable alloc] + initWithValueHandler:^(NSData *value) { + XCTFail(@"Received unexpected response: %@", value); + } + completionHandler:^(NSError *errorOrNil) { + XCTAssertNotNil(errorOrNil, @"Finished without error!"); + XCTAssertEqual(errorOrNil.code, 16, @"Finished with unexpected error: %@", errorOrNil); + XCTAssertEqualObjects(call.responseHeaders, errorOrNil.userInfo[kGRPCHeadersKey], + @"Headers in the NSError object and call object differ."); + XCTAssertEqualObjects(call.responseTrailers, errorOrNil.userInfo[kGRPCTrailersKey], + @"Trailers in the NSError object and call object differ."); + NSString *challengeHeader = call.oauth2ChallengeHeader; + XCTAssertGreaterThan(challengeHeader.length, 0, @"No challenge in response headers %@", + call.responseHeaders); + [expectation fulfill]; + }]; + + [call startWithWriteable:responsesWriteable]; + + [self waitForExpectationsWithTimeout:kTestTimeout handler:nil]; +} + +- (void)testErrorDebugInformation { + XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."]; + + RMTSimpleRequest *request = [RMTSimpleRequest message]; + request.fillUsername = YES; + request.fillOauthScope = YES; + GRXWriter *requestsWriter = [GRXWriter writerWithValue:[request data]]; + + GRPCCall *call = [[GRPCCall alloc] initWithHost:kRemoteSSLHost + path:kUnaryCallMethod.HTTPPath + requestsWriter:requestsWriter]; + + call.oauth2AccessToken = @"bogusToken"; + + id responsesWriteable = [[GRXWriteable alloc] + initWithValueHandler:^(NSData *value) { + XCTFail(@"Received unexpected response: %@", value); + } + completionHandler:^(NSError *errorOrNil) { + XCTAssertNotNil(errorOrNil, @"Finished without error!"); + NSDictionary *userInfo = errorOrNil.userInfo; + NSString *debugInformation = userInfo[NSDebugDescriptionErrorKey]; + XCTAssertNotNil(debugInformation); + XCTAssertNotEqual([debugInformation length], 0); + NSString *challengeHeader = call.oauth2ChallengeHeader; + XCTAssertGreaterThan(challengeHeader.length, 0, @"No challenge in response headers %@", + call.responseHeaders); + [expectation fulfill]; + }]; + + [call startWithWriteable:responsesWriteable]; + + [self waitForExpectationsWithTimeout:kTestTimeout handler:nil]; +} + @end diff --git a/src/objective-c/tests/UnitTests/APIv2Tests.m b/src/objective-c/tests/UnitTests/APIv2Tests.m index fa3f9ad61b8..51c87fe55b0 100644 --- a/src/objective-c/tests/UnitTests/APIv2Tests.m +++ b/src/objective-c/tests/UnitTests/APIv2Tests.m @@ -24,6 +24,7 @@ #include #include +#import "../Common/GRPCBlockCallbackResponseHandler.h" #import "../Common/TestUtils.h" #import "../version.h" @@ -50,81 +51,6 @@ static const NSTimeInterval kInvertedTimeout = 2; @end -// Convenience class to use blocks as callbacks -@interface ClientTestsBlockCallbacks : NSObject - -- (instancetype)initWithInitialMetadataCallback:(void (^)(NSDictionary *))initialMetadataCallback - messageCallback:(void (^)(id))messageCallback - closeCallback:(void (^)(NSDictionary *, NSError *))closeCallback - writeDataCallback:(void (^)(void))writeDataCallback; - -- (instancetype)initWithInitialMetadataCallback:(void (^)(NSDictionary *))initialMetadataCallback - messageCallback:(void (^)(id))messageCallback - closeCallback:(void (^)(NSDictionary *, NSError *))closeCallback; - -@end - -@implementation ClientTestsBlockCallbacks { - void (^_initialMetadataCallback)(NSDictionary *); - void (^_messageCallback)(id); - void (^_closeCallback)(NSDictionary *, NSError *); - void (^_writeDataCallback)(void); - dispatch_queue_t _dispatchQueue; -} - -- (instancetype)initWithInitialMetadataCallback:(void (^)(NSDictionary *))initialMetadataCallback - messageCallback:(void (^)(id))messageCallback - closeCallback:(void (^)(NSDictionary *, NSError *))closeCallback - writeDataCallback:(void (^)(void))writeDataCallback { - if ((self = [super init])) { - _initialMetadataCallback = initialMetadataCallback; - _messageCallback = messageCallback; - _closeCallback = closeCallback; - _writeDataCallback = writeDataCallback; - _dispatchQueue = dispatch_queue_create(nil, DISPATCH_QUEUE_SERIAL); - } - return self; -} - -- (instancetype)initWithInitialMetadataCallback:(void (^)(NSDictionary *))initialMetadataCallback - messageCallback:(void (^)(id))messageCallback - closeCallback:(void (^)(NSDictionary *, NSError *))closeCallback { - return [self initWithInitialMetadataCallback:initialMetadataCallback - messageCallback:messageCallback - closeCallback:closeCallback - writeDataCallback:nil]; -} - -- (void)didReceiveInitialMetadata:(NSDictionary *)initialMetadata { - if (self->_initialMetadataCallback) { - self->_initialMetadataCallback(initialMetadata); - } -} - -- (void)didReceiveRawMessage:(GPBMessage *)message { - if (self->_messageCallback) { - self->_messageCallback(message); - } -} - -- (void)didCloseWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error { - if (self->_closeCallback) { - self->_closeCallback(trailingMetadata, error); - } -} - -- (void)didWriteData { - if (self->_writeDataCallback) { - self->_writeDataCallback(); - } -} - -- (dispatch_queue_t)dispatchQueue { - return _dispatchQueue; -} - -@end - @interface CallAPIv2Tests : XCTestCase @end @@ -154,55 +80,6 @@ static const NSTimeInterval kInvertedTimeout = 2; method:@"FullDuplexCall"]; } -- (void)testMetadata { - __weak XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."]; - - RMTSimpleRequest *request = [RMTSimpleRequest message]; - request.fillUsername = YES; - request.fillOauthScope = YES; - - GRPCRequestOptions *callRequest = - [[GRPCRequestOptions alloc] initWithHost:GRPCGetRemoteInteropTestServerAddress() - path:kUnaryCallMethod.HTTPPath - safety:GRPCCallSafetyDefault]; - __block NSDictionary *init_md; - __block NSDictionary *trailing_md; - GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - options.oauth2AccessToken = @"bogusToken"; - GRPCCall2 *call = [[GRPCCall2 alloc] - initWithRequestOptions:callRequest - responseHandler:[[ClientTestsBlockCallbacks alloc] - initWithInitialMetadataCallback:^(NSDictionary *initialMetadata) { - init_md = initialMetadata; - } - messageCallback:^(id message) { - XCTFail(@"Received unexpected response."); - } - closeCallback:^(NSDictionary *trailingMetadata, NSError *error) { - trailing_md = trailingMetadata; - if (error) { - XCTAssertEqual(error.code, 16, - @"Finished with unexpected error: %@", error); - XCTAssertEqualObjects(init_md, - error.userInfo[kGRPCHeadersKey]); - XCTAssertEqualObjects(trailing_md, - error.userInfo[kGRPCTrailersKey]); - NSString *challengeHeader = init_md[@"www-authenticate"]; - XCTAssertGreaterThan(challengeHeader.length, 0, - @"No challenge in response headers %@", - init_md); - [expectation fulfill]; - } - }] - callOptions:options]; - - [call start]; - [call writeData:[request data]]; - [call finish]; - - [self waitForExpectationsWithTimeout:kTestTimeout handler:nil]; -} - - (void)testUserAgentPrefix { __weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."]; __weak XCTestExpectation *recvInitialMd = @@ -221,7 +98,7 @@ static const NSTimeInterval kInvertedTimeout = 2; GRPCCall2 *call = [[GRPCCall2 alloc] initWithRequestOptions:request responseHandler: - [[ClientTestsBlockCallbacks alloc] + [[GRPCBlockCallbackResponseHandler alloc] initWithInitialMetadataCallback:^(NSDictionary *initialMetadata) { NSString *userAgent = initialMetadata[@"x-grpc-test-echo-useragent"]; // Test the regex is correct @@ -293,7 +170,7 @@ static const NSTimeInterval kInvertedTimeout = 2; options.authTokenProvider = self; __block GRPCCall2 *call = [[GRPCCall2 alloc] initWithRequestOptions:requestOptions - responseHandler:[[ClientTestsBlockCallbacks alloc] + responseHandler:[[GRPCBlockCallbackResponseHandler alloc] initWithInitialMetadataCallback:nil messageCallback:nil closeCallback:^(NSDictionary *trailingMetadata, @@ -325,7 +202,7 @@ static const NSTimeInterval kInvertedTimeout = 2; GRPCCall2 *call = [[GRPCCall2 alloc] initWithRequestOptions:requestOptions - responseHandler:[[ClientTestsBlockCallbacks alloc] + responseHandler:[[GRPCBlockCallbackResponseHandler alloc] initWithInitialMetadataCallback:nil messageCallback:nil closeCallback:^(NSDictionary *trailingMetadata, @@ -358,7 +235,7 @@ static const NSTimeInterval kInvertedTimeout = 2; GRPCCall2 *call = [[GRPCCall2 alloc] initWithRequestOptions:requestOptions responseHandler: - [[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil + [[GRPCBlockCallbackResponseHandler alloc] initWithInitialMetadataCallback:nil messageCallback:^(NSData *data) { XCTFail(@"Failure: response received; Expect: no response received."); } @@ -396,7 +273,8 @@ static const NSTimeInterval kInvertedTimeout = 2; NSDate *startTime = [NSDate date]; GRPCCall2 *call = [[GRPCCall2 alloc] initWithRequestOptions:requestOptions - responseHandler:[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil + responseHandler:[[GRPCBlockCallbackResponseHandler alloc] + initWithInitialMetadataCallback:nil messageCallback:^(NSData *data) { XCTFail(@"Received message. Should not reach here."); } @@ -443,7 +321,8 @@ static const NSTimeInterval kInvertedTimeout = 2; options.compressionAlgorithm = GRPCCompressGzip; GRPCCall2 *call = [[GRPCCall2 alloc] initWithRequestOptions:requestOptions - responseHandler:[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil + responseHandler:[[GRPCBlockCallbackResponseHandler alloc] + initWithInitialMetadataCallback:nil messageCallback:^(NSData *data) { NSError *error; RMTSimpleResponse *response = @@ -484,7 +363,7 @@ static const NSTimeInterval kInvertedTimeout = 2; options.flowControlEnabled = YES; GRPCCall2 *call = [[GRPCCall2 alloc] initWithRequestOptions:callRequest - responseHandler:[[ClientTestsBlockCallbacks alloc] + responseHandler:[[GRPCBlockCallbackResponseHandler alloc] initWithInitialMetadataCallback:nil messageCallback:nil closeCallback:nil @@ -527,7 +406,8 @@ static const NSTimeInterval kInvertedTimeout = 2; __block int unblocked = NO; GRPCCall2 *call = [[GRPCCall2 alloc] initWithRequestOptions:callRequest - responseHandler:[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil + responseHandler:[[GRPCBlockCallbackResponseHandler alloc] + initWithInitialMetadataCallback:nil messageCallback:^(NSData *message) { if (!unblocked) { [expectBlockedMessage fulfill]; @@ -586,22 +466,23 @@ static const NSTimeInterval kInvertedTimeout = 2; options.transportType = GRPCTransportTypeInsecure; options.flowControlEnabled = YES; __block NSUInteger messageId = 0; - __block GRPCCall2 *call = [[GRPCCall2 alloc] - initWithRequestOptions:callRequest - responseHandler:[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil - messageCallback:^(NSData *message) { - if (messageId <= 1) { - [expectPassedMessage fulfill]; - } else { - [expectBlockedMessage fulfill]; - } - messageId++; - } - closeCallback:nil - writeDataCallback:^{ - [expectWriteTwice fulfill]; - }] - callOptions:options]; + __block GRPCCall2 *call = + [[GRPCCall2 alloc] initWithRequestOptions:callRequest + responseHandler:[[GRPCBlockCallbackResponseHandler alloc] + initWithInitialMetadataCallback:nil + messageCallback:^(NSData *message) { + if (messageId <= 1) { + [expectPassedMessage fulfill]; + } else { + [expectBlockedMessage fulfill]; + } + messageId++; + } + closeCallback:nil + writeDataCallback:^{ + [expectWriteTwice fulfill]; + }] + callOptions:options]; [call receiveNextMessages:2]; [call start]; @@ -631,7 +512,8 @@ static const NSTimeInterval kInvertedTimeout = 2; __block BOOL closed = NO; GRPCCall2 *call = [[GRPCCall2 alloc] initWithRequestOptions:callRequest - responseHandler:[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil + responseHandler:[[GRPCBlockCallbackResponseHandler alloc] + initWithInitialMetadataCallback:nil messageCallback:^(NSData *message) { [expectPassedMessage fulfill]; XCTAssertFalse(closed); @@ -672,7 +554,8 @@ static const NSTimeInterval kInvertedTimeout = 2; __block BOOL closed = NO; GRPCCall2 *call = [[GRPCCall2 alloc] initWithRequestOptions:callRequest - responseHandler:[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil + responseHandler:[[GRPCBlockCallbackResponseHandler alloc] + initWithInitialMetadataCallback:nil messageCallback:^(NSData *message) { [expectPassedMessage fulfill]; XCTAssertFalse(closed); @@ -712,7 +595,8 @@ static const NSTimeInterval kInvertedTimeout = 2; GRPCCall2 *call = [[GRPCCall2 alloc] initWithRequestOptions:requestOptions - responseHandler:[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil + responseHandler:[[GRPCBlockCallbackResponseHandler alloc] + initWithInitialMetadataCallback:nil messageCallback:^(NSData *data) { XCTFail(@"Received unexpected message"); } diff --git a/src/objective-c/tests/UnitTests/GRPCClientTests.m b/src/objective-c/tests/UnitTests/GRPCClientTests.m index 88aef0f2e5f..de687e471a8 100644 --- a/src/objective-c/tests/UnitTests/GRPCClientTests.m +++ b/src/objective-c/tests/UnitTests/GRPCClientTests.m @@ -44,7 +44,6 @@ static NSString *const kHostAddress = NSStringize(HOST_PORT_LOCAL); static NSString *const kPackage = @"grpc.testing"; static NSString *const kService = @"TestService"; -static NSString *const kRemoteSSLHost = NSStringize(HOST_PORT_REMOTE); static GRPCProtoMethod *kInexistentMethod; static GRPCProtoMethod *kEmptyCallMethod; @@ -210,42 +209,6 @@ static GRPCProtoMethod *kFullDuplexCallMethod; [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; } -- (void)testMetadata { - __weak XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."]; - - RMTSimpleRequest *request = [RMTSimpleRequest message]; - request.fillUsername = YES; - request.fillOauthScope = YES; - GRXWriter *requestsWriter = [GRXWriter writerWithValue:[request data]]; - - GRPCCall *call = [[GRPCCall alloc] initWithHost:kRemoteSSLHost - path:kUnaryCallMethod.HTTPPath - requestsWriter:requestsWriter]; - - call.oauth2AccessToken = @"bogusToken"; - - id responsesWriteable = [[GRXWriteable alloc] - initWithValueHandler:^(NSData *value) { - XCTFail(@"Received unexpected response: %@", value); - } - completionHandler:^(NSError *errorOrNil) { - XCTAssertNotNil(errorOrNil, @"Finished without error!"); - XCTAssertEqual(errorOrNil.code, 16, @"Finished with unexpected error: %@", errorOrNil); - XCTAssertEqualObjects(call.responseHeaders, errorOrNil.userInfo[kGRPCHeadersKey], - @"Headers in the NSError object and call object differ."); - XCTAssertEqualObjects(call.responseTrailers, errorOrNil.userInfo[kGRPCTrailersKey], - @"Trailers in the NSError object and call object differ."); - NSString *challengeHeader = call.oauth2ChallengeHeader; - XCTAssertGreaterThan(challengeHeader.length, 0, @"No challenge in response headers %@", - call.responseHeaders); - [expectation fulfill]; - }]; - - [call startWithWriteable:responsesWriteable]; - - [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; -} - - (void)testResponseMetadataKVO { __weak XCTestExpectation *response = [self expectationWithDescription:@"Empty response received."]; @@ -569,39 +532,4 @@ static GRPCProtoMethod *kFullDuplexCallMethod; [self testTimeoutBackoffWithTimeout:0.3 Backoff:0.7]; } -- (void)testErrorDebugInformation { - __weak XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."]; - - RMTSimpleRequest *request = [RMTSimpleRequest message]; - request.fillUsername = YES; - request.fillOauthScope = YES; - GRXWriter *requestsWriter = [GRXWriter writerWithValue:[request data]]; - - GRPCCall *call = [[GRPCCall alloc] initWithHost:kRemoteSSLHost - path:kUnaryCallMethod.HTTPPath - requestsWriter:requestsWriter]; - - call.oauth2AccessToken = @"bogusToken"; - - id responsesWriteable = [[GRXWriteable alloc] - initWithValueHandler:^(NSData *value) { - XCTFail(@"Received unexpected response: %@", value); - } - completionHandler:^(NSError *errorOrNil) { - XCTAssertNotNil(errorOrNil, @"Finished without error!"); - NSDictionary *userInfo = errorOrNil.userInfo; - NSString *debugInformation = userInfo[NSDebugDescriptionErrorKey]; - XCTAssertNotNil(debugInformation); - XCTAssertNotEqual([debugInformation length], 0); - NSString *challengeHeader = call.oauth2ChallengeHeader; - XCTAssertGreaterThan(challengeHeader.length, 0, @"No challenge in response headers %@", - call.responseHeaders); - [expectation fulfill]; - }]; - - [call startWithWriteable:responsesWriteable]; - - [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; -} - @end