From 7502bd29c3112c11796bf6516004e0ffb1a01842 Mon Sep 17 00:00:00 2001
From: Jorge Canizales <jcanizales@google.com>
Date: Tue, 3 Mar 2015 10:28:25 -0800
Subject: [PATCH] Asynchronous unit test

---
 .../examples/Sample/SampleTests/SampleTests.m | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/src/objective-c/examples/Sample/SampleTests/SampleTests.m b/src/objective-c/examples/Sample/SampleTests/SampleTests.m
index 9a1d4b14d4..e5e3bc72b2 100644
--- a/src/objective-c/examples/Sample/SampleTests/SampleTests.m
+++ b/src/objective-c/examples/Sample/SampleTests/SampleTests.m
@@ -34,6 +34,11 @@
 #import <UIKit/UIKit.h>
 #import <XCTest/XCTest.h>
 
+#import <gRPC/GRPCCall.h>
+#import <gRPC/GRPCMethodName.h>
+#import <RxLibrary/GRXWriter+Immediate.h>
+#import <RxLibrary/GRXWriteable.h>
+
 @interface SampleTests : XCTestCase
 
 @end
@@ -62,4 +67,35 @@
     }];
 }
 
+- (void)testConnectionToSandboxServer {
+  XCTestExpectation *expectation = [self expectationWithDescription:@"Server reachable."];
+  
+  GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:@"grpc.testing"
+                                                         interface:@"TestService"
+                                                            method:@"EmptyCall"];
+
+  id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[NSData data]];
+
+  GRPCCall *call = [[GRPCCall alloc] initWithHost:@"grpc-test.sandbox.google.com:443"
+                                           method:method
+                                   requestsWriter:requestsWriter];
+
+  id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+    NSLog(@"Received unexpected response: %@", value);
+  } completionHandler:^(NSError *errorOrNil) {
+    if (errorOrNil) {
+      NSLog(@"Finished with error: %@", errorOrNil);
+    } else {
+      [expectation fulfill];
+    }
+  }];
+
+  [call startWithWriteable:responsesWriteable];
+
+  [self waitForExpectationsWithTimeout:10.0 handler:^(NSError *error) {
+    if(error) {
+      XCTFail(@"Server unreachable. Error: %@", error);
+    }
+  }];
+}
 @end
-- 
GitLab