Only test the ObjC layer

pull/9247/head
Muxi Yan 8 years ago
parent bf803b9563
commit 40d7c627bd
  1. 15
      src/objective-c/GRPCClient/GRPCCall+Tests.h
  2. 37
      src/objective-c/GRPCClient/GRPCCall+Tests.m
  3. 4
      src/objective-c/GRPCClient/private/GRPCWrappedCall.m
  4. 43
      src/objective-c/tests/InteropTests.m

@ -63,4 +63,19 @@
* cache. * cache.
*/ */
+ (void)resetHostSettings; + (void)resetHostSettings;
/**
* Enables logging of op batches. Memory consumption increases as more ops are logged.
*/
+ (void)enableOpBatchLog:(BOOL)enabled;
/**
* Add an op batch to log.
*/
+ (void)addOpBatchToLog:(NSArray *)batch;
/**
* Obtain the logged op batches. Invoking this method will clean the log.
*/
+ (NSArray *)obtainAndCleanOpBatchLog;
@end @end

@ -64,4 +64,41 @@
+ (void)resetHostSettings { + (void)resetHostSettings {
[GRPCHost resetAllHostSettings]; [GRPCHost resetAllHostSettings];
} }
static NSMutableArray *opBatchLog = nil;
+ (void)enableOpBatchLog:(BOOL)enabled {
@synchronized (opBatchLog) {
if (enabled) {
if (!opBatchLog) {
opBatchLog = [NSMutableArray array];
}
} else {
if (opBatchLog) {
opBatchLog = nil;
}
}
}
}
+ (void)addOpBatchToLog:(NSArray *)batch {
@synchronized (opBatchLog) {
if (opBatchLog) {
[opBatchLog addObject:batch];
}
}
}
+ (NSArray *)obtainAndCleanOpBatchLog {
@synchronized (opBatchLog) {
if (opBatchLog) {
NSArray *out = opBatchLog;
opBatchLog = [NSMutableArray array];
return out;
} else {
return nil;
}
}
}
@end @end

@ -44,6 +44,8 @@
#import "NSData+GRPC.h" #import "NSData+GRPC.h"
#import "NSError+GRPC.h" #import "NSError+GRPC.h"
#import "GRPCCall+Tests.h"
@implementation GRPCOperation { @implementation GRPCOperation {
@protected @protected
// Most operation subclasses don't set any flags in the grpc_op, and rely on the flag member being // Most operation subclasses don't set any flags in the grpc_op, and rely on the flag member being
@ -271,6 +273,8 @@
} }
- (void)startBatchWithOperations:(NSArray *)operations errorHandler:(void (^)())errorHandler { - (void)startBatchWithOperations:(NSArray *)operations errorHandler:(void (^)())errorHandler {
[GRPCCall addOpBatchToLog:operations];
size_t nops = operations.count; size_t nops = operations.count;
grpc_op *ops_array = gpr_malloc(nops * sizeof(grpc_op)); grpc_op *ops_array = gpr_malloc(nops * sizeof(grpc_op));
size_t i = 0; size_t i = 0;

@ -145,32 +145,7 @@
[self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil];
} }
// TODO (mxyan): Do the same test for chttp2
#ifdef GRPC_COMPILE_WITH_CRONET
#ifdef GRPC_CRONET_WITH_PACKET_COALESCING
static bool coalesced_message_and_eos;
static void log_processor(gpr_log_func_args *args) {
unsigned long file_len = strlen(args->file);
const char suffix[] = "call.c";
const int suffix_len = sizeof(suffix) - 1;
const char nops[] = "nops=3";
if (file_len > suffix_len &&
0 == strcmp(suffix, &args->file[file_len - suffix_len]) &&
strstr(args->message, nops)) {
fprintf(stderr, "%s, %s\n", args->file, args->message);
coalesced_message_and_eos = true;
}
}
- (void)testPacketCoalescing { - (void)testPacketCoalescing {
gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG);
grpc_tracer_set_enabled("all", 1);
gpr_set_log_function(log_processor);
coalesced_message_and_eos = false;
XCTAssertNotNil(self.class.host); XCTAssertNotNil(self.class.host);
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"LargeUnary"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"LargeUnary"];
@ -179,6 +154,7 @@ static void log_processor(gpr_log_func_args *args) {
request.responseSize = 10; request.responseSize = 10;
request.payload.body = [NSMutableData dataWithLength:10]; request.payload.body = [NSMutableData dataWithLength:10];
[GRPCCall enableOpBatchLog:YES];
[_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) { [_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) {
XCTAssertNil(error, @"Finished with unexpected error: %@", error); XCTAssertNil(error, @"Finished with unexpected error: %@", error);
@ -187,17 +163,22 @@ static void log_processor(gpr_log_func_args *args) {
expectedResponse.payload.body = [NSMutableData dataWithLength:10]; expectedResponse.payload.body = [NSMutableData dataWithLength:10];
XCTAssertEqualObjects(response, expectedResponse); XCTAssertEqualObjects(response, expectedResponse);
XCTAssert(coalesced_message_and_eos); NSArray *opBatches = [GRPCCall obtainAndCleanOpBatchLog];
for (NSObject *o in opBatches) {
[expectation fulfill]; if ([o isKindOfClass:[NSArray class]]) {
NSArray *batch = (NSArray *)o;
if ([batch count] == 3) {
[expectation fulfill];
break;
}
}
}
}]; }];
[self waitForExpectationsWithTimeout:16 handler:nil]; [self waitForExpectationsWithTimeout:16 handler:nil];
[GRPCCall enableOpBatchLog:NO];
} }
#endif
#endif
- (void)test4MBResponsesAreAccepted { - (void)test4MBResponsesAreAccepted {
XCTAssertNotNil(self.class.host); XCTAssertNotNil(self.class.host);
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"MaxResponseSize"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"MaxResponseSize"];

Loading…
Cancel
Save