|
|
|
@ -80,10 +80,6 @@ |
|
|
|
|
|
|
|
|
|
#pragma mark Tests |
|
|
|
|
|
|
|
|
|
#ifdef GRPC_COMPILE_WITH_CRONET |
|
|
|
|
static cronet_engine *cronetEngine = NULL; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
@implementation InteropTests { |
|
|
|
|
RMTTestService *_service; |
|
|
|
|
} |
|
|
|
@ -92,15 +88,22 @@ static cronet_engine *cronetEngine = NULL; |
|
|
|
|
return nil; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (int32_t)encodingOverhead { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)setUp { |
|
|
|
|
self.continueAfterFailure = NO; |
|
|
|
|
|
|
|
|
|
[GRPCCall resetHostSettings]; |
|
|
|
|
|
|
|
|
|
_service = self.class.host ? [RMTTestService serviceWithHost:self.class.host] : nil; |
|
|
|
|
#ifdef GRPC_COMPILE_WITH_CRONET |
|
|
|
|
if (cronetEngine == NULL) { |
|
|
|
|
// Cronet setup |
|
|
|
|
[Cronet setHttp2Enabled:YES]; |
|
|
|
|
[Cronet start]; |
|
|
|
|
cronetEngine = [Cronet getGlobalEngine]; |
|
|
|
|
[GRPCCall useCronetWithEngine:cronetEngine]; |
|
|
|
|
[GRPCCall useCronetWithEngine:[Cronet getGlobalEngine]]; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
@ -146,6 +149,64 @@ static cronet_engine *cronetEngine = NULL; |
|
|
|
|
[self waitForExpectationsWithTimeout:16 handler:nil]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)test4MBResponsesAreAccepted { |
|
|
|
|
XCTAssertNotNil(self.class.host); |
|
|
|
|
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"MaxResponseSize"]; |
|
|
|
|
|
|
|
|
|
RMTSimpleRequest *request = [RMTSimpleRequest message]; |
|
|
|
|
const int32_t kPayloadSize = 4 * 1024 * 1024 - self.encodingOverhead; // 4MB - encoding overhead |
|
|
|
|
request.responseSize = kPayloadSize; |
|
|
|
|
|
|
|
|
|
[_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) { |
|
|
|
|
XCTAssertNil(error, @"Finished with unexpected error: %@", error); |
|
|
|
|
XCTAssertEqual(response.payload.body.length, kPayloadSize); |
|
|
|
|
[expectation fulfill]; |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
[self waitForExpectationsWithTimeout:16 handler:nil]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)testResponsesOverMaxSizeFailWithActionableMessage { |
|
|
|
|
XCTAssertNotNil(self.class.host); |
|
|
|
|
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"ResponseOverMaxSize"]; |
|
|
|
|
|
|
|
|
|
RMTSimpleRequest *request = [RMTSimpleRequest message]; |
|
|
|
|
const int32_t kPayloadSize = 4 * 1024 * 1024 - self.encodingOverhead + 1; // 1B over max size |
|
|
|
|
request.responseSize = kPayloadSize; |
|
|
|
|
|
|
|
|
|
[_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) { |
|
|
|
|
// TODO(jcanizales): Catch the error and rethrow it with an actionable message: |
|
|
|
|
// - Use +[GRPCCall setResponseSizeLimit:forHost:] to set a higher limit. |
|
|
|
|
// - If you're developing the server, consider using response streaming, or let clients filter |
|
|
|
|
// responses by setting a google.protobuf.FieldMask in the request: |
|
|
|
|
// https://github.com/google/protobuf/blob/master/src/google/protobuf/field_mask.proto |
|
|
|
|
XCTAssertEqualObjects(error.localizedDescription, @"Max message size exceeded"); |
|
|
|
|
[expectation fulfill]; |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
[self waitForExpectationsWithTimeout:16 handler:nil]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)testResponsesOver4MBAreAcceptedIfOptedIn { |
|
|
|
|
XCTAssertNotNil(self.class.host); |
|
|
|
|
__weak XCTestExpectation *expectation = |
|
|
|
|
[self expectationWithDescription:@"HigherResponseSizeLimit"]; |
|
|
|
|
|
|
|
|
|
RMTSimpleRequest *request = [RMTSimpleRequest message]; |
|
|
|
|
const size_t kPayloadSize = 5 * 1024 * 1024; // 5MB |
|
|
|
|
request.responseSize = kPayloadSize; |
|
|
|
|
|
|
|
|
|
[GRPCCall setResponseSizeLimit:6 * 1024 * 1024 forHost:self.class.host]; |
|
|
|
|
|
|
|
|
|
[_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) { |
|
|
|
|
XCTAssertNil(error, @"Finished with unexpected error: %@", error); |
|
|
|
|
XCTAssertEqual(response.payload.body.length, kPayloadSize); |
|
|
|
|
[expectation fulfill]; |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
[self waitForExpectationsWithTimeout:16 handler:nil]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)testClientStreamingRPC { |
|
|
|
|
XCTAssertNotNil(self.class.host); |
|
|
|
|
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"ClientStreaming"]; |
|
|
|
|