From 895f3d83da12664e59379d9ce6cccb8ab9f244b7 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Wed, 5 Apr 2017 13:12:30 -0700 Subject: Support configuring dispatch queue in GRPCCall and below --- src/objective-c/GRPCClient/GRPCCall.h | 7 +++++++ src/objective-c/GRPCClient/GRPCCall.m | 16 +++++++++++++++- src/objective-c/RxLibrary/GRXConcurrentWriteable.h | 4 +++- src/objective-c/RxLibrary/GRXConcurrentWriteable.m | 10 ++++++++-- 4 files changed, 33 insertions(+), 4 deletions(-) (limited to 'src/objective-c') diff --git a/src/objective-c/GRPCClient/GRPCCall.h b/src/objective-c/GRPCClient/GRPCCall.h index 7645bb1d34..85c5b47c8e 100644 --- a/src/objective-c/GRPCClient/GRPCCall.h +++ b/src/objective-c/GRPCClient/GRPCCall.h @@ -253,6 +253,13 @@ extern id const kGRPCTrailersKey; */ + (void)setCallSafety:(GRPCCallSafety)callSafety host:(NSString *)host path:(NSString *)path; +/** + * Set the dispatch queue to be used for queue responses. + * + * This configuration is only effective before the call starts. + */ +- (void)setResponseDispatchQueue:(dispatch_queue_t)queue; + // TODO(jcanizales): Let specify a deadline. As a category of GRXWriter? @end diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m index 051138ea4d..f9d13fea57 100644 --- a/src/objective-c/GRPCClient/GRPCCall.m +++ b/src/objective-c/GRPCClient/GRPCCall.m @@ -113,6 +113,10 @@ static NSMutableDictionary *callFlags; // the SendClose op is added. BOOL _unaryCall; NSMutableArray *_unaryOpBatch; + + // The dispatch queue to be used for enqueuing responses to user. Defaulted to the main dispatch + // queue + dispatch_queue_t _responseQueue; } @synthesize state = _state; @@ -175,10 +179,19 @@ static NSMutableDictionary *callFlags; _unaryCall = YES; _unaryOpBatch = [NSMutableArray arrayWithCapacity:kMaxClientBatch]; } + + _responseQueue = dispatch_get_main_queue(); } return self; } +- (void)setResponseDispatchQueue:(dispatch_queue_t)queue { + if (_state != GRXWriterStateNotStarted) { + return; + } + _responseQueue = queue; +} + #pragma mark Finish - (void)finishWithError:(NSError *)errorOrNil { @@ -424,7 +437,8 @@ static NSMutableDictionary *callFlags; // that the life of the instance is determined by this retain cycle. _retainSelf = self; - _responseWriteable = [[GRXConcurrentWriteable alloc] initWithWriteable:writeable]; + _responseWriteable = [[GRXConcurrentWriteable alloc] initWithWriteable:writeable + dispatchQueue:_responseQueue]; _wrappedCall = [[GRPCWrappedCall alloc] initWithHost:_host path:_path]; NSAssert(_wrappedCall, @"Error allocating RPC objects. Low memory?"); diff --git a/src/objective-c/RxLibrary/GRXConcurrentWriteable.h b/src/objective-c/RxLibrary/GRXConcurrentWriteable.h index b2775f98b5..07004f6d4d 100644 --- a/src/objective-c/RxLibrary/GRXConcurrentWriteable.h +++ b/src/objective-c/RxLibrary/GRXConcurrentWriteable.h @@ -53,7 +53,9 @@ * The GRXWriteable instance is retained until writesFinishedWithError: is sent to it, and released * after that. */ -- (instancetype)initWithWriteable:(id)writeable NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithWriteable:(id)writeable + dispatchQueue:(dispatch_queue_t)queue NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithWriteable:(id)writeable; /** * Enqueues writeValue: to be sent to the writeable in the main thread. diff --git a/src/objective-c/RxLibrary/GRXConcurrentWriteable.m b/src/objective-c/RxLibrary/GRXConcurrentWriteable.m index 08bd079aea..88aa7a7282 100644 --- a/src/objective-c/RxLibrary/GRXConcurrentWriteable.m +++ b/src/objective-c/RxLibrary/GRXConcurrentWriteable.m @@ -51,14 +51,20 @@ } // Designated initializer -- (instancetype)initWithWriteable:(id)writeable { +- (instancetype)initWithWriteable:(id)writeable + dispatchQueue:(dispatch_queue_t)queue { if (self = [super init]) { - _writeableQueue = dispatch_get_main_queue(); + _writeableQueue = queue; _writeable = writeable; } return self; } +- (instancetype)initWithWriteable:(id)writeable { + return [self initWithWriteable:writeable + dispatchQueue:dispatch_get_main_queue()]; +} + - (void)enqueueValue:(id)value completionHandler:(void (^)())handler { dispatch_async(_writeableQueue, ^{ // We're racing a possible cancellation performed by another thread. To turn all already- -- cgit v1.2.3 From e1ed7712102363d5e6fdad31b1016119f95f0631 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Thu, 6 Apr 2017 11:52:55 -0700 Subject: Add test --- src/objective-c/tests/InteropTests.m | 95 ++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) (limited to 'src/objective-c') diff --git a/src/objective-c/tests/InteropTests.m b/src/objective-c/tests/InteropTests.m index 9105356869..4466d6810c 100644 --- a/src/objective-c/tests/InteropTests.m +++ b/src/objective-c/tests/InteropTests.m @@ -457,4 +457,99 @@ [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; } +- (void)testAlternateDispatchQueue { + XCTAssertNotNil(self.class.host); + __weak XCTestExpectation *expectation1 = [self expectationWithDescription:@"AlternateDispatchQueue1"]; + + NSArray *requests = @[@27182, @8, @1828, @45904]; + NSArray *responses = @[@31415, @9, @2653, @58979]; + + // Set the default dispatch queue + NSString *queue1_label = @"test.queue1"; + NSString *queue2_label = @"test.queue2"; + dispatch_queue_t queue1 = dispatch_queue_create([queue1_label UTF8String], DISPATCH_QUEUE_SERIAL); + dispatch_queue_t queue2 = dispatch_queue_create([queue2_label UTF8String], DISPATCH_QUEUE_SERIAL); + [_service setDefaultResponseDispatchQueue:queue1]; + GRXBufferedPipe *requestsBuffer1 = [[GRXBufferedPipe alloc] init]; + + __block int index = 0; + + id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] + requestedResponseSize:responses[index]]; + [requestsBuffer1 writeValue:request]; + + [_service fullDuplexCallWithRequestsWriter:requestsBuffer1 + eventHandler:^(BOOL done, + RMTStreamingOutputCallResponse *response, + NSError *error) { + XCTAssertNil(error, @"Finished with unexpected error: %@", error); + XCTAssertTrue(done || response, @"Event handler called without an event."); + NSString *label = [NSString stringWithUTF8String:dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)]; + XCTAssert([label isEqualToString:queue1_label]); + + if (response) { + XCTAssertLessThan(index, 4, @"More than 4 responses received."); + id expected = [RMTStreamingOutputCallResponse messageWithPayloadSize:responses[index]]; + XCTAssertEqualObjects(response, expected); + index += 1; + if (index < 4) { + id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] + requestedResponseSize:responses[index]]; + [requestsBuffer1 writeValue:request]; + } else { + [requestsBuffer1 writesFinishedWithError:nil]; + } + } + + if (done) { + XCTAssertEqual(index, 4, @"Received %i responses instead of 4.", index); + [expectation1 fulfill]; + } + }]; + + [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; + + // Test overriding default queue with another queue + __weak XCTestExpectation *expectation2 = [self expectationWithDescription:@"AlternateDispatchQueue2"]; + GRXBufferedPipe *requestsBuffer2 = [[GRXBufferedPipe alloc] init]; + + index = 0; + + [requestsBuffer2 writeValue:request]; + + GRPCProtoCall *rpc = [_service RPCToFullDuplexCallWithRequestsWriter:requestsBuffer2 + eventHandler:^(BOOL done, + RMTStreamingOutputCallResponse *response, + NSError *error) { + XCTAssertNil(error, @"Finished with unexpected error: %@", error); + XCTAssertTrue(done || response, @"Event handler called without an event."); + NSString *label = [NSString stringWithUTF8String:dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)]; + XCTAssert([label isEqualToString:queue2_label]); + + if (response) { + XCTAssertLessThan(index, 4, @"More than 4 responses received."); + id expected = [RMTStreamingOutputCallResponse messageWithPayloadSize:responses[index]]; + XCTAssertEqualObjects(response, expected); + index += 1; + if (index < 4) { + id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] + requestedResponseSize:responses[index]]; + [requestsBuffer2 writeValue:request]; + } else { + [requestsBuffer2 writesFinishedWithError:nil]; + } + } + + if (done) { + XCTAssertEqual(index, 4, @"Received %i responses instead of 4.", index); + [expectation2 fulfill]; + } + }]; + [rpc setResponseDispatchQueue:queue2]; + [rpc start]; + + [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; + [_service setDefaultResponseDispatchQueue:dispatch_get_main_queue()]; +} + @end -- cgit v1.2.3 From 880530694192f9be13b8767bfab7a06fdda9697e Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Wed, 19 Apr 2017 13:50:06 -0700 Subject: Revert API to change default queue for a stub --- src/compiler/objective_c_generator.cc | 34 +++++------------- src/objective-c/tests/InteropTests.m | 68 +++++++---------------------------- 2 files changed, 21 insertions(+), 81 deletions(-) (limited to 'src/objective-c') diff --git a/src/compiler/objective_c_generator.cc b/src/compiler/objective_c_generator.cc index ba89b28b7b..1d7faf120d 100644 --- a/src/compiler/objective_c_generator.cc +++ b/src/compiler/objective_c_generator.cc @@ -149,20 +149,17 @@ void PrintMethodDeclarations(Printer *printer, const MethodDescriptor *method) { void PrintSimpleImplementation(Printer *printer, const MethodDescriptor *method, map< ::grpc::string, ::grpc::string> vars) { printer->Print("{\n"); - printer->Print(vars, " GRPCProtoCall *rpc = [self RPCTo$method_name$With"); + printer->Print(vars, " [[self RPCTo$method_name$With"); if (method->client_streaming()) { printer->Print("RequestsWriter:requestWriter"); } else { printer->Print("Request:request"); } if (method->server_streaming()) { - printer->Print(" eventHandler:eventHandler];\n"); + printer->Print(" eventHandler:eventHandler] start];\n"); } else { - printer->Print(" handler:handler];\n"); + printer->Print(" handler:handler] start];\n"); } - printer->Print( - " [rpc setResponseDispatchQueue:_defaultResponseDispatchQueue];\n"); - printer->Print(" [rpc start];\n"); printer->Print("}\n"); } @@ -170,29 +167,23 @@ void PrintAdvancedImplementation(Printer *printer, const MethodDescriptor *method, map< ::grpc::string, ::grpc::string> vars) { printer->Print("{\n"); - printer->Print( - vars, " GRPCProtoCall *rpc = [self RPCToMethod:@\"$method_name$\"\n"); + printer->Print(vars, " return [self RPCToMethod:@\"$method_name$\"\n"); - printer->Print(" requestsWriter:"); + printer->Print(" requestsWriter:"); if (method->client_streaming()) { printer->Print("requestWriter\n"); } else { printer->Print("[GRXWriter writerWithValue:request]\n"); } - printer->Print( - vars, - " responseClass:[$response_class$ class]\n"); + printer->Print(vars, " responseClass:[$response_class$ class]\n"); - printer->Print(" responsesWriteable:[GRXWriteable "); + printer->Print(" responsesWriteable:[GRXWriteable "); if (method->server_streaming()) { printer->Print("writeableWithEventHandler:eventHandler]];\n"); } else { printer->Print("writeableWithSingleHandler:handler]];\n"); } - printer->Print( - " [rpc setResponseDispatchQueue:_defaultResponseDispatchQueue];\n"); - printer->Print(" return rpc;\n"); printer->Print("}\n"); } @@ -243,8 +234,6 @@ void PrintMethodImplementations(Printer *printer, "- (instancetype)initWithHost:(NSString *)host" " NS_DESIGNATED_INITIALIZER;\n"); printer.Print("+ (instancetype)serviceWithHost:(NSString *)host;\n"); - printer.Print( - "- (void)setDefaultResponseDispatchQueue:(dispatch_queue_t)queue;\n"); printer.Print("@end\n"); } return output; @@ -262,15 +251,12 @@ void PrintMethodImplementations(Printer *printer, {"service_class", ServiceClassName(service)}, {"package", service->file()->package()}}; - printer.Print(vars, "@implementation $service_class$ {\n"); - printer.Print(vars, " dispatch_queue_t _defaultResponseDispatchQueue;\n"); - printer.Print(vars, "}\n\n"); + printer.Print(vars, "@implementation $service_class$\n\n"); printer.Print("// Designated initializer\n"); printer.Print("- (instancetype)initWithHost:(NSString *)host {\n"); printer.Print( vars, - " _defaultResponseDispatchQueue = dispatch_get_main_queue();\n" " return (self = [super initWithHost:host" " packageName:@\"$package$\" serviceName:@\"$service_name$\"]);\n"); printer.Print("}\n\n"); @@ -284,10 +270,6 @@ void PrintMethodImplementations(Printer *printer, printer.Print("}\n\n"); printer.Print("+ (instancetype)serviceWithHost:(NSString *)host {\n"); printer.Print(" return [[self alloc] initWithHost:host];\n"); - printer.Print("}\n\n"); - printer.Print( - "- (void)setDefaultResponseDispatchQueue:(dispatch_queue_t)queue {\n"); - printer.Print(" _defaultResponseDispatchQueue = queue;\n"); printer.Print("}\n\n\n"); for (int i = 0; i < service->method_count(); i++) { diff --git a/src/objective-c/tests/InteropTests.m b/src/objective-c/tests/InteropTests.m index 4466d6810c..e7d28f4e45 100644 --- a/src/objective-c/tests/InteropTests.m +++ b/src/objective-c/tests/InteropTests.m @@ -459,23 +459,17 @@ - (void)testAlternateDispatchQueue { XCTAssertNotNil(self.class.host); - __weak XCTestExpectation *expectation1 = [self expectationWithDescription:@"AlternateDispatchQueue1"]; + NSNumber *kPayloadSize = @256; + id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:kPayloadSize + requestedResponseSize:kPayloadSize]; - NSArray *requests = @[@27182, @8, @1828, @45904]; - NSArray *responses = @[@31415, @9, @2653, @58979]; + __weak XCTestExpectation *expectation1 = [self expectationWithDescription:@"AlternateDispatchQueue1"]; // Set the default dispatch queue - NSString *queue1_label = @"test.queue1"; - NSString *queue2_label = @"test.queue2"; - dispatch_queue_t queue1 = dispatch_queue_create([queue1_label UTF8String], DISPATCH_QUEUE_SERIAL); - dispatch_queue_t queue2 = dispatch_queue_create([queue2_label UTF8String], DISPATCH_QUEUE_SERIAL); - [_service setDefaultResponseDispatchQueue:queue1]; + NSString *queue_label = @"test.queue1"; + dispatch_queue_t queue = dispatch_queue_create([queue_label UTF8String], DISPATCH_QUEUE_SERIAL); GRXBufferedPipe *requestsBuffer1 = [[GRXBufferedPipe alloc] init]; - __block int index = 0; - - id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] - requestedResponseSize:responses[index]]; [requestsBuffer1 writeValue:request]; [_service fullDuplexCallWithRequestsWriter:requestsBuffer1 @@ -485,26 +479,11 @@ XCTAssertNil(error, @"Finished with unexpected error: %@", error); XCTAssertTrue(done || response, @"Event handler called without an event."); NSString *label = [NSString stringWithUTF8String:dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)]; - XCTAssert([label isEqualToString:queue1_label]); - - if (response) { - XCTAssertLessThan(index, 4, @"More than 4 responses received."); - id expected = [RMTStreamingOutputCallResponse messageWithPayloadSize:responses[index]]; - XCTAssertEqualObjects(response, expected); - index += 1; - if (index < 4) { - id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] - requestedResponseSize:responses[index]]; - [requestsBuffer1 writeValue:request]; - } else { - [requestsBuffer1 writesFinishedWithError:nil]; - } - } + NSLog(@"main queue label:%@", label); + NSString *main_queue_label = [NSString stringWithUTF8String:dispatch_queue_get_label(dispatch_get_main_queue())]; + XCTAssert([label isEqualToString:main_queue_label]); - if (done) { - XCTAssertEqual(index, 4, @"Received %i responses instead of 4.", index); - [expectation1 fulfill]; - } + [expectation1 fulfill]; }]; [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; @@ -513,8 +492,6 @@ __weak XCTestExpectation *expectation2 = [self expectationWithDescription:@"AlternateDispatchQueue2"]; GRXBufferedPipe *requestsBuffer2 = [[GRXBufferedPipe alloc] init]; - index = 0; - [requestsBuffer2 writeValue:request]; GRPCProtoCall *rpc = [_service RPCToFullDuplexCallWithRequestsWriter:requestsBuffer2 @@ -524,32 +501,13 @@ XCTAssertNil(error, @"Finished with unexpected error: %@", error); XCTAssertTrue(done || response, @"Event handler called without an event."); NSString *label = [NSString stringWithUTF8String:dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)]; - XCTAssert([label isEqualToString:queue2_label]); - - if (response) { - XCTAssertLessThan(index, 4, @"More than 4 responses received."); - id expected = [RMTStreamingOutputCallResponse messageWithPayloadSize:responses[index]]; - XCTAssertEqualObjects(response, expected); - index += 1; - if (index < 4) { - id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] - requestedResponseSize:responses[index]]; - [requestsBuffer2 writeValue:request]; - } else { - [requestsBuffer2 writesFinishedWithError:nil]; - } - } - - if (done) { - XCTAssertEqual(index, 4, @"Received %i responses instead of 4.", index); - [expectation2 fulfill]; - } + XCTAssert([label isEqualToString:queue_label]); + [expectation2 fulfill]; }]; - [rpc setResponseDispatchQueue:queue2]; + [rpc setResponseDispatchQueue:queue]; [rpc start]; [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; - [_service setDefaultResponseDispatchQueue:dispatch_get_main_queue()]; } @end -- cgit v1.2.3 From b965ff6bf764c9144862af6e4fb25bd90ecd6f55 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Wed, 19 Apr 2017 14:27:47 -0700 Subject: Move test to GRPCClientTests --- src/objective-c/tests/GRPCClientTests.m | 55 +++++++++++++++++++++++++++++++++ src/objective-c/tests/InteropTests.m | 53 ------------------------------- 2 files changed, 55 insertions(+), 53 deletions(-) (limited to 'src/objective-c') diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m index 76c15003f6..0a631d182a 100644 --- a/src/objective-c/tests/GRPCClientTests.m +++ b/src/objective-c/tests/GRPCClientTests.m @@ -353,4 +353,59 @@ static GRPCProtoMethod *kUnaryCallMethod; [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; } +- (void)testAlternateDispatchQueue { + const int32_t kPayloadSize = 100; + RMTSimpleRequest *request = [RMTSimpleRequest message]; + request.responseSize = kPayloadSize; + + __weak XCTestExpectation *expectation1 = [self expectationWithDescription:@"AlternateDispatchQueue1"]; + + // Use default (main) dispatch queue + NSString *main_queue_label = [NSString stringWithUTF8String:dispatch_queue_get_label(dispatch_get_main_queue())]; + + GRXWriter *requestsWriter1 = [GRXWriter writerWithValue:[request data]]; + + GRPCCall *call1 = [[GRPCCall alloc] initWithHost:kHostAddress + path:kUnaryCallMethod.HTTPPath + requestsWriter:requestsWriter1]; + + id responsesWriteable1 = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) { + NSString *label = [NSString stringWithUTF8String:dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)]; + XCTAssert([label isEqualToString:main_queue_label]); + + [expectation1 fulfill]; + } completionHandler:^(NSError *errorOrNil) { + }]; + + [call1 startWithWriteable:responsesWriteable1]; + + [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; + + // Use a custom queue + __weak XCTestExpectation *expectation2 = [self expectationWithDescription:@"AlternateDispatchQueue2"]; + + NSString *queue_label = @"test.queue1"; + dispatch_queue_t queue = dispatch_queue_create([queue_label UTF8String], DISPATCH_QUEUE_SERIAL); + + GRXWriter *requestsWriter2 = [GRXWriter writerWithValue:[request data]]; + + GRPCCall *call2 = [[GRPCCall alloc] initWithHost:kHostAddress + path:kUnaryCallMethod.HTTPPath + requestsWriter:requestsWriter2]; + + [call2 setResponseDispatchQueue:queue]; + + id responsesWriteable2 = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) { + NSString *label = [NSString stringWithUTF8String:dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)]; + XCTAssert([label isEqualToString:queue_label]); + + [expectation2 fulfill]; + } completionHandler:^(NSError *errorOrNil) { + }]; + + [call2 startWithWriteable:responsesWriteable2]; + + [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; +} + @end diff --git a/src/objective-c/tests/InteropTests.m b/src/objective-c/tests/InteropTests.m index e7d28f4e45..9105356869 100644 --- a/src/objective-c/tests/InteropTests.m +++ b/src/objective-c/tests/InteropTests.m @@ -457,57 +457,4 @@ [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; } -- (void)testAlternateDispatchQueue { - XCTAssertNotNil(self.class.host); - NSNumber *kPayloadSize = @256; - id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:kPayloadSize - requestedResponseSize:kPayloadSize]; - - __weak XCTestExpectation *expectation1 = [self expectationWithDescription:@"AlternateDispatchQueue1"]; - - // Set the default dispatch queue - NSString *queue_label = @"test.queue1"; - dispatch_queue_t queue = dispatch_queue_create([queue_label UTF8String], DISPATCH_QUEUE_SERIAL); - GRXBufferedPipe *requestsBuffer1 = [[GRXBufferedPipe alloc] init]; - - [requestsBuffer1 writeValue:request]; - - [_service fullDuplexCallWithRequestsWriter:requestsBuffer1 - eventHandler:^(BOOL done, - RMTStreamingOutputCallResponse *response, - NSError *error) { - XCTAssertNil(error, @"Finished with unexpected error: %@", error); - XCTAssertTrue(done || response, @"Event handler called without an event."); - NSString *label = [NSString stringWithUTF8String:dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)]; - NSLog(@"main queue label:%@", label); - NSString *main_queue_label = [NSString stringWithUTF8String:dispatch_queue_get_label(dispatch_get_main_queue())]; - XCTAssert([label isEqualToString:main_queue_label]); - - [expectation1 fulfill]; - }]; - - [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; - - // Test overriding default queue with another queue - __weak XCTestExpectation *expectation2 = [self expectationWithDescription:@"AlternateDispatchQueue2"]; - GRXBufferedPipe *requestsBuffer2 = [[GRXBufferedPipe alloc] init]; - - [requestsBuffer2 writeValue:request]; - - GRPCProtoCall *rpc = [_service RPCToFullDuplexCallWithRequestsWriter:requestsBuffer2 - eventHandler:^(BOOL done, - RMTStreamingOutputCallResponse *response, - NSError *error) { - XCTAssertNil(error, @"Finished with unexpected error: %@", error); - XCTAssertTrue(done || response, @"Event handler called without an event."); - NSString *label = [NSString stringWithUTF8String:dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)]; - XCTAssert([label isEqualToString:queue_label]); - [expectation2 fulfill]; - }]; - [rpc setResponseDispatchQueue:queue]; - [rpc start]; - - [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; -} - @end -- cgit v1.2.3 From a2529ce53ae729b1ebcc0fa241ec9671c891dad1 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Wed, 19 Apr 2017 14:32:47 -0700 Subject: Minor comment polish --- src/objective-c/GRPCClient/GRPCCall.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/objective-c') diff --git a/src/objective-c/GRPCClient/GRPCCall.h b/src/objective-c/GRPCClient/GRPCCall.h index 85c5b47c8e..5e9324c445 100644 --- a/src/objective-c/GRPCClient/GRPCCall.h +++ b/src/objective-c/GRPCClient/GRPCCall.h @@ -254,7 +254,7 @@ extern id const kGRPCTrailersKey; + (void)setCallSafety:(GRPCCallSafety)callSafety host:(NSString *)host path:(NSString *)path; /** - * Set the dispatch queue to be used for queue responses. + * Set the dispatch queue to be used for callbacks. * * This configuration is only effective before the call starts. */ -- cgit v1.2.3 From fd00263ae91d93e7dea28c6b7f229201e46463b5 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Thu, 20 Apr 2017 16:16:49 -0700 Subject: Fix nit --- src/objective-c/tests/GRPCClientTests.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/objective-c') diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m index 0a631d182a..e36f5c3ee9 100644 --- a/src/objective-c/tests/GRPCClientTests.m +++ b/src/objective-c/tests/GRPCClientTests.m @@ -366,8 +366,8 @@ static GRPCProtoMethod *kUnaryCallMethod; GRXWriter *requestsWriter1 = [GRXWriter writerWithValue:[request data]]; GRPCCall *call1 = [[GRPCCall alloc] initWithHost:kHostAddress - path:kUnaryCallMethod.HTTPPath - requestsWriter:requestsWriter1]; + path:kUnaryCallMethod.HTTPPath + requestsWriter:requestsWriter1]; id responsesWriteable1 = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) { NSString *label = [NSString stringWithUTF8String:dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)]; -- cgit v1.2.3