diff options
author | Muxi Yan <muxi@users.noreply.github.com> | 2018-04-10 09:57:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-10 09:57:18 -0700 |
commit | b0db704e6004c32163151d2794e7a64ccade2447 (patch) | |
tree | e93b218304e94bd1887567cce207937a7611a551 /src/objective-c | |
parent | 74d31d7b7a22357b9aa41cde1540af541a67f4f8 (diff) | |
parent | 109bb09da3c96149a6d722b4d06466542965049a (diff) |
Merge pull request #14942 from muxi/fix-objc-status
Fix gRPC ObjC return status
Diffstat (limited to 'src/objective-c')
-rw-r--r-- | src/objective-c/GRPCClient/GRPCCall.m | 24 | ||||
-rw-r--r-- | src/objective-c/tests/GRPCClientTests.m | 38 |
2 files changed, 42 insertions, 20 deletions
diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m index cf70064298..501114dea0 100644 --- a/src/objective-c/GRPCClient/GRPCCall.m +++ b/src/objective-c/GRPCClient/GRPCCall.m @@ -355,17 +355,8 @@ static NSString * const kBearerPrefix = @"Bearer "; } dispatch_async(_callQueue, ^{ - __weak GRPCCall *weakSelf = self; - [self writeMessage:value withErrorHandler:^{ - __strong GRPCCall *strongSelf = weakSelf; - if (strongSelf != nil) { - [strongSelf maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain - code:GRPCErrorCodeInternal - userInfo:nil]]; - // Wrapped call must be canceled when error is reported to upper layers - [strongSelf cancelCall]; - } - }]; + // Write error is not processed here. It is handled by op batch of GRPC_OP_RECV_STATUS_ON_CLIENT + [self writeMessage:value withErrorHandler:nil]; }); } @@ -387,15 +378,8 @@ static NSString * const kBearerPrefix = @"Bearer "; [self cancel]; } else { dispatch_async(_callQueue, ^{ - __weak GRPCCall *weakSelf = self; - [self finishRequestWithErrorHandler:^{ - __strong GRPCCall *strongSelf = weakSelf; - [strongSelf maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain - code:GRPCErrorCodeInternal - userInfo:nil]]; - // Wrapped call must be canceled when error is reported to upper layers - [strongSelf cancelCall]; - }]; + // EOS error is not processed here. It is handled by op batch of GRPC_OP_RECV_STATUS_ON_CLIENT + [self finishRequestWithErrorHandler:nil]; }); } } 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 |