From b965ff6bf764c9144862af6e4fb25bd90ecd6f55 Mon Sep 17 00:00:00 2001
From: Muxi Yan <mxyan@google.com>
Date: Wed, 19 Apr 2017 14:27:47 -0700
Subject: [PATCH] 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(-)

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
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
-- 
GitLab