aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/examples
diff options
context:
space:
mode:
authorGravatar Jorge Canizales <jcanizales@google.com>2015-03-03 10:28:25 -0800
committerGravatar Jorge Canizales <jcanizales@google.com>2015-04-21 09:51:17 -0700
commit7502bd29c3112c11796bf6516004e0ffb1a01842 (patch)
tree478cc8491f73d287a479336458e809f984fdfe89 /src/objective-c/examples
parent1d3734934ff45a2c2552751ed3f05f9a5813baf3 (diff)
Asynchronous unit test
Diffstat (limited to 'src/objective-c/examples')
-rw-r--r--src/objective-c/examples/Sample/SampleTests/SampleTests.m36
1 files changed, 36 insertions, 0 deletions
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