aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/tests/GRPCClientTests.m
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2017-04-19 14:27:47 -0700
committerGravatar Muxi Yan <mxyan@google.com>2017-04-19 14:27:47 -0700
commitb965ff6bf764c9144862af6e4fb25bd90ecd6f55 (patch)
treef2369ca55af563707734d3f6ad47b805e1836226 /src/objective-c/tests/GRPCClientTests.m
parent880530694192f9be13b8767bfab7a06fdda9697e (diff)
Move test to GRPCClientTests
Diffstat (limited to 'src/objective-c/tests/GRPCClientTests.m')
-rw-r--r--src/objective-c/tests/GRPCClientTests.m55
1 files changed, 55 insertions, 0 deletions
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<GRXWriteable> 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<GRXWriteable> 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