aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/tests
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2018-04-04 15:16:30 -0700
committerGravatar Muxi Yan <mxyan@google.com>2018-04-04 16:18:45 -0700
commit109bb09da3c96149a6d722b4d06466542965049a (patch)
tree53a027431646ceeb3a8451ef3418b5705f001b5a /src/objective-c/tests
parent5860671868f003835f77ac03a3f90336044e9329 (diff)
Surface return status from core
Diffstat (limited to 'src/objective-c/tests')
-rw-r--r--src/objective-c/tests/GRPCClientTests.m38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m
index 3bab7f6671..e716198009 100644
--- a/src/objective-c/tests/GRPCClientTests.m
+++ b/src/objective-c/tests/GRPCClientTests.m
@@ -31,6 +31,8 @@
#import <RxLibrary/GRXWriter+Immediate.h>
#import <RxLibrary/GRXBufferedPipe.h>
+#include <netinet/in.h>
+
#import "version.h"
#define TEST_TIMEOUT 16
@@ -482,4 +484,40 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
}
+- (int)findFreePort {
+ struct sockaddr_in addr;
+ unsigned int addr_len = sizeof(addr);
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ int fd = socket(AF_INET, SOCK_STREAM, 0);
+ XCTAssertEqual(bind(fd, (struct sockaddr*)&addr, sizeof(addr)), 0);
+ XCTAssertEqual(getsockname(fd, (struct sockaddr*)&addr, &addr_len), 0);
+ XCTAssertEqual(addr_len, sizeof(addr));
+ close(fd);
+ return addr.sin_port;
+}
+
+- (void)testErrorCode {
+ int port = [self findFreePort];
+ NSString * const kDummyAddress = [NSString stringWithFormat:@"localhost:%d", port];
+ __weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."];
+
+ GRPCCall *call = [[GRPCCall alloc] initWithHost:kDummyAddress
+ path:kEmptyCallMethod.HTTPPath
+ requestsWriter:[GRXWriter writerWithValue:[NSData data]]];
+
+ id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ // Should not reach here
+ XCTAssert(NO);
+ } completionHandler:^(NSError *errorOrNil) {
+ XCTAssertNotNil(errorOrNil, @"Finished with no error");
+ XCTAssertEqual(errorOrNil.code, GRPC_STATUS_UNAVAILABLE);
+ [completion fulfill];
+ }];
+
+ [call startWithWriteable:responsesWriteable];
+
+ [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
+}
+
@end