3 * Copyright 2018 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #import <XCTest/XCTest.h>
21 #import <RemoteTest/Messages.pbobjc.h>
22 #import <RemoteTest/Test.pbobjc.h>
23 #import <RemoteTest/Test.pbrpc.h>
24 #import <RxLibrary/GRXBufferedPipe.h>
25 #import <RxLibrary/GRXWriter+Immediate.h>
28 #define NSStringize_helper(x) #x
29 #define NSStringize(x) @NSStringize_helper(x)
30 static NSString *kRemoteHost = NSStringize(HOST_PORT_REMOTE);
31 const int32_t kRemoteInteropServerOverhead = 12;
33 static const NSTimeInterval TEST_TIMEOUT = 16000;
35 @interface InteropTestsCallOptions : XCTestCase
39 @implementation InteropTestsCallOptions {
40 RMTTestService *_service;
44 self.continueAfterFailure = NO;
45 _service = [RMTTestService serviceWithHost:kRemoteHost];
46 _service.options = [[GRPCCallOptions alloc] init];
49 - (void)test4MBResponsesAreAccepted {
50 __weak XCTestExpectation *expectation = [self expectationWithDescription:@"MaxResponseSize"];
52 RMTSimpleRequest *request = [RMTSimpleRequest message];
53 const int32_t kPayloadSize =
54 4 * 1024 * 1024 - kRemoteInteropServerOverhead; // 4MB - encoding overhead
55 request.responseSize = kPayloadSize;
57 [_service unaryCallWithRequest:request
58 handler:^(RMTSimpleResponse *response, NSError *error) {
59 XCTAssertNil(error, @"Finished with unexpected error: %@", error);
60 XCTAssertEqual(response.payload.body.length, kPayloadSize);
61 [expectation fulfill];
64 [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
67 - (void)testResponsesOverMaxSizeFailWithActionableMessage {
68 __weak XCTestExpectation *expectation = [self expectationWithDescription:@"ResponseOverMaxSize"];
70 RMTSimpleRequest *request = [RMTSimpleRequest message];
71 const int32_t kPayloadSize =
72 4 * 1024 * 1024 - kRemoteInteropServerOverhead + 1; // 1B over max size
73 request.responseSize = kPayloadSize;
75 [_service unaryCallWithRequest:request
76 handler:^(RMTSimpleResponse *response, NSError *error) {
77 XCTAssertEqualObjects(
78 error.localizedDescription,
79 @"Received message larger than max (4194305 vs. 4194304)");
80 [expectation fulfill];
83 [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
86 - (void)testResponsesOver4MBAreAcceptedIfOptedIn {
87 __weak XCTestExpectation *expectation =
88 [self expectationWithDescription:@"HigherResponseSizeLimit"];
90 RMTSimpleRequest *request = [RMTSimpleRequest message];
91 const size_t kPayloadSize = 5 * 1024 * 1024; // 5MB
92 request.responseSize = kPayloadSize;
94 GRPCProtoCall *rpc = [_service
95 RPCToUnaryCallWithRequest:request
96 handler:^(RMTSimpleResponse *response, NSError *error) {
97 XCTAssertNil(error, @"Finished with unexpected error: %@", error);
98 XCTAssertEqual(response.payload.body.length, kPayloadSize);
99 [expectation fulfill];
101 GRPCCallOptions *options = rpc.options;
102 options.responseSizeLimit = 6 * 1024 * 1024;
106 [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
109 - (void)testPerformanceExample {
110 // This is an example of a performance test case.
111 [self measureBlock:^{
112 // Put the code you want to measure the time of here.