aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/tests/GRPCClientTests.m
diff options
context:
space:
mode:
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..e36f5c3ee9 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