|
|
|
@ -446,42 +446,40 @@ static GRPCProtoMethod *kFullDuplexCallMethod; |
|
|
|
|
options.initialMetadata = headers; |
|
|
|
|
GRPCCall2 *call = [[GRPCCall2 alloc] |
|
|
|
|
initWithRequestOptions:request |
|
|
|
|
responseHandler:[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:^( |
|
|
|
|
responseHandler:[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:^( |
|
|
|
|
NSDictionary *initialMetadata) { |
|
|
|
|
NSString *userAgent = initialMetadata[@"x-grpc-test-echo-useragent"]; |
|
|
|
|
// Test the regex is correct |
|
|
|
|
NSString *expectedUserAgent = @"Foo grpc-objc/"; |
|
|
|
|
expectedUserAgent = |
|
|
|
|
[expectedUserAgent stringByAppendingString:GRPC_OBJC_VERSION_STRING]; |
|
|
|
|
expectedUserAgent = [expectedUserAgent stringByAppendingString:@" grpc-c/"]; |
|
|
|
|
expectedUserAgent = |
|
|
|
|
[expectedUserAgent stringByAppendingString:GRPC_C_VERSION_STRING]; |
|
|
|
|
expectedUserAgent = |
|
|
|
|
[expectedUserAgent stringByAppendingString:@" (ios; chttp2; "]; |
|
|
|
|
expectedUserAgent = [expectedUserAgent |
|
|
|
|
stringByAppendingString:[NSString |
|
|
|
|
stringWithUTF8String:grpc_g_stands_for()]]; |
|
|
|
|
expectedUserAgent = [expectedUserAgent stringByAppendingString:@")"]; |
|
|
|
|
XCTAssertEqualObjects(userAgent, expectedUserAgent); |
|
|
|
|
|
|
|
|
|
NSError *error = nil; |
|
|
|
|
// Change in format of user-agent field in a direction that does not match |
|
|
|
|
// the regex will likely cause problem for certain gRPC users. For details, |
|
|
|
|
// refer to internal doc https://goo.gl/c2diBc |
|
|
|
|
NSRegularExpression *regex = [NSRegularExpression |
|
|
|
|
regularExpressionWithPattern: |
|
|
|
|
@" grpc-[a-zA-Z0-9]+(-[a-zA-Z0-9]+)?/[^ ,]+( \\([^)]*\\))?" |
|
|
|
|
options:0 |
|
|
|
|
error:&error]; |
|
|
|
|
|
|
|
|
|
NSString *customUserAgent = [regex |
|
|
|
|
stringByReplacingMatchesInString:userAgent |
|
|
|
|
options:0 |
|
|
|
|
range:NSMakeRange(0, [userAgent length]) |
|
|
|
|
withTemplate:@""]; |
|
|
|
|
XCTAssertEqualObjects(customUserAgent, @"Foo"); |
|
|
|
|
[recvInitialMd fulfill]; |
|
|
|
|
} |
|
|
|
|
NSString *userAgent = initialMetadata[@"x-grpc-test-echo-useragent"]; |
|
|
|
|
// Test the regex is correct |
|
|
|
|
NSString *expectedUserAgent = @"Foo grpc-objc/"; |
|
|
|
|
expectedUserAgent = |
|
|
|
|
[expectedUserAgent stringByAppendingString:GRPC_OBJC_VERSION_STRING]; |
|
|
|
|
expectedUserAgent = [expectedUserAgent stringByAppendingString:@" grpc-c/"]; |
|
|
|
|
expectedUserAgent = |
|
|
|
|
[expectedUserAgent stringByAppendingString:GRPC_C_VERSION_STRING]; |
|
|
|
|
expectedUserAgent = [expectedUserAgent stringByAppendingString:@" (ios; chttp2; "]; |
|
|
|
|
expectedUserAgent = [expectedUserAgent |
|
|
|
|
stringByAppendingString:[NSString stringWithUTF8String:grpc_g_stands_for()]]; |
|
|
|
|
expectedUserAgent = [expectedUserAgent stringByAppendingString:@")"]; |
|
|
|
|
XCTAssertEqualObjects(userAgent, expectedUserAgent); |
|
|
|
|
|
|
|
|
|
NSError *error = nil; |
|
|
|
|
// Change in format of user-agent field in a direction that does not match |
|
|
|
|
// the regex will likely cause problem for certain gRPC users. For details, |
|
|
|
|
// refer to internal doc https://goo.gl/c2diBc |
|
|
|
|
NSRegularExpression *regex = [NSRegularExpression |
|
|
|
|
regularExpressionWithPattern: |
|
|
|
|
@" grpc-[a-zA-Z0-9]+(-[a-zA-Z0-9]+)?/[^ ,]+( \\([^)]*\\))?" |
|
|
|
|
options:0 |
|
|
|
|
error:&error]; |
|
|
|
|
|
|
|
|
|
NSString *customUserAgent = |
|
|
|
|
[regex stringByReplacingMatchesInString:userAgent |
|
|
|
|
options:0 |
|
|
|
|
range:NSMakeRange(0, [userAgent length]) |
|
|
|
|
withTemplate:@""]; |
|
|
|
|
XCTAssertEqualObjects(customUserAgent, @"Foo"); |
|
|
|
|
[recvInitialMd fulfill]; |
|
|
|
|
} |
|
|
|
|
messageCallback:^(id message) { |
|
|
|
|
XCTAssertNotNil(message); |
|
|
|
|
XCTAssertEqual([message length], 0, |
|
|
|
@ -609,7 +607,7 @@ static GRPCProtoMethod *kFullDuplexCallMethod; |
|
|
|
|
options.transportType = GRPCTransportTypeInsecure; |
|
|
|
|
GRPCCall2 *call = [[GRPCCall2 alloc] |
|
|
|
|
initWithRequestOptions:requestOptions |
|
|
|
|
responseHandler:[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil |
|
|
|
|
responseHandler:[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil |
|
|
|
|
messageCallback:^(id message) { |
|
|
|
|
NSData *data = (NSData *)message; |
|
|
|
|
XCTAssertNotNil(data, @"nil value received as response."); |
|
|
|
@ -739,19 +737,18 @@ static GRPCProtoMethod *kFullDuplexCallMethod; |
|
|
|
|
|
|
|
|
|
GRPCCall2 *call = [[GRPCCall2 alloc] |
|
|
|
|
initWithRequestOptions:requestOptions |
|
|
|
|
responseHandler: |
|
|
|
|
[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil |
|
|
|
|
messageCallback:^(id data) { |
|
|
|
|
XCTFail( |
|
|
|
|
@"Failure: response received; Expect: no response received."); |
|
|
|
|
} |
|
|
|
|
closeCallback:^(NSDictionary *trailingMetadata, NSError *error) { |
|
|
|
|
XCTAssertNotNil(error, |
|
|
|
|
@"Failure: no error received; Expect: receive " |
|
|
|
|
@"deadline exceeded."); |
|
|
|
|
XCTAssertEqual(error.code, GRPCErrorCodeDeadlineExceeded); |
|
|
|
|
[completion fulfill]; |
|
|
|
|
}] |
|
|
|
|
responseHandler: |
|
|
|
|
[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil |
|
|
|
|
messageCallback:^(id data) { |
|
|
|
|
XCTFail(@"Failure: response received; Expect: no response received."); |
|
|
|
|
} |
|
|
|
|
closeCallback:^(NSDictionary *trailingMetadata, NSError *error) { |
|
|
|
|
XCTAssertNotNil(error, |
|
|
|
|
@"Failure: no error received; Expect: receive " |
|
|
|
|
@"deadline exceeded."); |
|
|
|
|
XCTAssertEqual(error.code, GRPCErrorCodeDeadlineExceeded); |
|
|
|
|
[completion fulfill]; |
|
|
|
|
}] |
|
|
|
|
callOptions:options]; |
|
|
|
|
|
|
|
|
|
[call start]; |
|
|
|
@ -837,7 +834,9 @@ static GRPCProtoMethod *kFullDuplexCallMethod; |
|
|
|
|
__weak XCTestExpectation *completion = [self expectationWithDescription:@"Timeout in a second."]; |
|
|
|
|
NSString *const kDummyAddress = [NSString stringWithFormat:@"127.0.0.1:10000"]; |
|
|
|
|
GRPCRequestOptions *requestOptions = |
|
|
|
|
[[GRPCRequestOptions alloc] initWithHost:kDummyAddress path:@"/dummy/path" safety:GRPCCallSafetyDefault]; |
|
|
|
|
[[GRPCRequestOptions alloc] initWithHost:kDummyAddress |
|
|
|
|
path:@"/dummy/path" |
|
|
|
|
safety:GRPCCallSafetyDefault]; |
|
|
|
|
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; |
|
|
|
|
options.connectMinTimeout = timeout; |
|
|
|
|
options.connectInitialBackoff = backoff; |
|
|
|
@ -846,7 +845,7 @@ static GRPCProtoMethod *kFullDuplexCallMethod; |
|
|
|
|
NSDate *startTime = [NSDate date]; |
|
|
|
|
GRPCCall2 *call = [[GRPCCall2 alloc] |
|
|
|
|
initWithRequestOptions:requestOptions |
|
|
|
|
responseHandler:[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil |
|
|
|
|
responseHandler:[[ClientTestsBlockCallbacks alloc] initWithInitialMetadataCallback:nil |
|
|
|
|
messageCallback:^(id data) { |
|
|
|
|
XCTFail(@"Received message. Should not reach here."); |
|
|
|
|
} |
|
|
|
|