aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/examples/Sample
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2015-05-20 11:59:20 -0700
committerGravatar murgatroid99 <mlumish@google.com>2015-05-20 11:59:20 -0700
commitdbfe2f437c532548ac3d4ecc21737fd6419a217f (patch)
treedad5553da75f2e70e406cf262e1f4619506282ae /src/objective-c/examples/Sample
parenta42c1fe8aeddff6e1fe13b7ee2d990999f2867c6 (diff)
Added cancel_after_first_response test
Diffstat (limited to 'src/objective-c/examples/Sample')
-rw-r--r--src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m b/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m
index 7e063fddb4..4fbaf63168 100644
--- a/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m
+++ b/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m
@@ -269,4 +269,37 @@
[self waitForExpectationsWithTimeout:1 handler:nil];
}
+- (void)testCancelAfterFirstResponseRPC {
+ __weak XCTestExpectation *expectation = [self expectationWithDescription:@"CancelAfterFirstResponse"];
+
+ // A buffered pipe to which we never write any value acts as a writer that just hangs.
+ GRXBufferedPipe *requestsBuffer = [[GRXBufferedPipe alloc] init];
+
+ __block bool receivedResponse = false;
+
+ id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:@21782
+ requestedResponseSize:@31415];
+
+ [requestsBuffer writeValue:request];
+
+ __block ProtoRPC *call = [_service RPCToFullDuplexCallWithRequestsWriter:requestsBuffer
+ handler:^(BOOL done,
+ RMTStreamingOutputCallResponse *response,
+ NSError *error) {
+ if (receivedResponse) {
+ XCTAssert(done, @"Unexpected extra response %@", response);
+ XCTAssertEqual(error.code, GRPC_STATUS_CANCELLED);
+ [expectation fulfill];
+ } else {
+ XCTAssertNil(error, @"Finished with unexpected error: %@", error);
+ XCTAssertFalse(done, @"Finished without response");
+ XCTAssertNotNil(response);
+ receivedResponse = true;
+ [call cancel];
+ }
+ }];
+ [call start];
+ [self waitForExpectationsWithTimeout:4 handler:nil];
+}
+
@end