[objc] Better test reporting with current test case instance (#30381)

pull/30376/head
Denny C. Dai 2 years ago committed by GitHub
parent f3c57aab0a
commit daee661f3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/objective-c/tests/Common/TestUtils.h
  2. 16
      src/objective-c/tests/Common/TestUtils.m
  3. 121
      src/objective-c/tests/InteropTests/InteropTests.m
  4. 12
      src/objective-c/tests/InteropTests/InteropTestsRemote.m

@ -25,8 +25,7 @@ NS_ASSUME_NONNULL_BEGIN
FOUNDATION_EXPORT const NSTimeInterval GRPCInteropTestTimeoutDefault; FOUNDATION_EXPORT const NSTimeInterval GRPCInteropTestTimeoutDefault;
// Block typedef for waiting for a target group of expectations via XCTWaiter. // Block typedef for waiting for a target group of expectations via XCTWaiter.
typedef void (^GRPCTestWaiter)(XCTestCase *testCase, NSArray<XCTestExpectation *> *expectations, typedef void (^GRPCTestWaiter)(NSArray<XCTestExpectation *> *expectations, NSTimeInterval timeout);
NSTimeInterval timeout);
// Block typedef for asserting a given expression value with optional retry. // Block typedef for asserting a given expression value with optional retry.
typedef void (^GRPCTestAssert)(BOOL expressionValue, NSString *message); typedef void (^GRPCTestAssert)(BOOL expressionValue, NSString *message);
@ -64,11 +63,13 @@ FOUNDATION_EXPORT void GRPCPrintInteropTestServerDebugInfo(void);
/** /**
* Common utility to run a test block until success, up to predefined number of repeats. * Common utility to run a test block until success, up to predefined number of repeats.
* @param testCase Associated test case run for reporting test failures.
* @param testBlock Target test block to be invoked by the utility function. The block will be * @param testBlock Target test block to be invoked by the utility function. The block will be
* invoked synchronously before the function returns. * invoked synchronously before the function returns.
* @return YES if test run succeeded within the repeat limit. NO otherwise. * @return YES if test run succeeded within the repeat limit. NO otherwise.
*/ */
FOUNDATION_EXPORT BOOL GRPCTestRunWithFlakeRepeats(GRPCTestRunBlock testBlock); FOUNDATION_EXPORT BOOL GRPCTestRunWithFlakeRepeats(XCTestCase *testCase,
GRPCTestRunBlock testBlock);
/** /**
* Common utility to reset gRPC call's active connections. * Common utility to reset gRPC call's active connections.

@ -74,14 +74,6 @@ static NSUInteger GRPCGetTestFlakeRepeats() {
return repeats; return repeats;
} }
// Helper function to assert failure via XCTest
static void GRPCAssertFail(NSString *message) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnonnull"
_XCTPrimitiveFail(nil, @"%@", message);
#pragma GCC diagnostic pop
}
void GRPCResetCallConnections() { void GRPCResetCallConnections() {
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wdeprecated-declarations"
@ -100,7 +92,7 @@ void GRPCPrintInteropTestServerDebugInfo() {
NSStringize(HOST_PORT_REMOTE)); NSStringize(HOST_PORT_REMOTE));
} }
BOOL GRPCTestRunWithFlakeRepeats(GRPCTestRunBlock testBlock) { BOOL GRPCTestRunWithFlakeRepeats(XCTestCase *testCase, GRPCTestRunBlock testBlock) {
NSInteger repeats = GRPCGetTestFlakeRepeats(); NSInteger repeats = GRPCGetTestFlakeRepeats();
NSInteger runs = 0; NSInteger runs = 0;
@ -111,8 +103,8 @@ BOOL GRPCTestRunWithFlakeRepeats(GRPCTestRunBlock testBlock) {
__block XCTWaiterResult result; __block XCTWaiterResult result;
__block BOOL assertionSuccess = YES; __block BOOL assertionSuccess = YES;
GRPCTestWaiter waiterBlock = ^(XCTestCase *testCase, NSArray<XCTestExpectation *> *expectations, GRPCTestWaiter waiterBlock =
NSTimeInterval timeout) { ^(NSArray<XCTestExpectation *> *expectations, NSTimeInterval timeout) {
if (isLastRun) { if (isLastRun) {
XCTWaiter *waiter = [[XCTWaiter alloc] initWithDelegate:testCase]; XCTWaiter *waiter = [[XCTWaiter alloc] initWithDelegate:testCase];
result = [waiter waitForExpectations:expectations timeout:timeout]; result = [waiter waitForExpectations:expectations timeout:timeout];
@ -125,7 +117,7 @@ BOOL GRPCTestRunWithFlakeRepeats(GRPCTestRunBlock testBlock) {
BOOL result = !!(expressionValue); BOOL result = !!(expressionValue);
assertionSuccess = assertionSuccess && result; assertionSuccess = assertionSuccess && result;
if (isLastRun && !result) { if (isLastRun && !result) {
GRPCAssertFail(message); _XCTPrimitiveFail(testCase, @"%@", message);
} }
}; };

@ -464,7 +464,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
} }
- (void)testEmptyUnaryRPC { - (void)testEmptyUnaryRPC {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiter, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiter, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"];
@ -484,12 +484,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
[expectation fulfill]; [expectation fulfill];
}]; }];
waiter(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiter(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testEmptyUnaryRPCWithV2API { - (void)testEmptyUnaryRPCWithV2API {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectReceive = __weak XCTestExpectation *expectReceive =
[self expectationWithDescription:@"EmptyUnaryWithV2API received message"]; [self expectationWithDescription:@"EmptyUnaryWithV2API received message"];
@ -527,13 +527,13 @@ static dispatch_once_t initGlobalInterceptorFactory;
}] }]
callOptions:options]; callOptions:options];
[call start]; [call start];
waiterBlock(self, @[ expectReceive, expectComplete ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectReceive, expectComplete ], GRPCInteropTestTimeoutDefault);
}); });
} }
// Test that responses can be dispatched even if we do not run main run-loop // Test that responses can be dispatched even if we do not run main run-loop
- (void)testAsyncDispatchWithV2API { - (void)testAsyncDispatchWithV2API {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
XCTestExpectation *receiveExpect = [self expectationWithDescription:@"receiveExpect"]; XCTestExpectation *receiveExpect = [self expectationWithDescription:@"receiveExpect"];
@ -576,14 +576,14 @@ static dispatch_once_t initGlobalInterceptorFactory;
[call start]; [call start];
waiterBlock(self, @[ receiveExpect, closeExpect ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ receiveExpect, closeExpect ], GRPCInteropTestTimeoutDefault);
XCTAssertTrue(messageReceived); XCTAssertTrue(messageReceived);
XCTAssertTrue(done); XCTAssertTrue(done);
}); });
} }
- (void)testLargeUnaryRPC { - (void)testLargeUnaryRPC {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"LargeUnary"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"LargeUnary"];
@ -609,7 +609,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
[expectation fulfill]; [expectation fulfill];
}]; }];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
@ -619,7 +619,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
return; return;
} }
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
XCTestExpectation *expectComplete = [self expectationWithDescription:@"call complete"]; XCTestExpectation *expectComplete = [self expectationWithDescription:@"call complete"];
@ -688,12 +688,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
[[service unaryCallWithMessage:request responseHandler:handlerMainQueue [[service unaryCallWithMessage:request responseHandler:handlerMainQueue
callOptions:options] start]; callOptions:options] start];
waiterBlock(self, @[ expectComplete, expectCompleteMainQueue ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectComplete, expectCompleteMainQueue ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testLargeUnaryRPCWithV2API { - (void)testLargeUnaryRPCWithV2API {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectReceive = __weak XCTestExpectation *expectReceive =
[self expectationWithDescription:@"LargeUnaryWithV2API received message"]; [self expectationWithDescription:@"LargeUnaryWithV2API received message"];
@ -741,12 +741,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
}] }]
callOptions:options]; callOptions:options];
[call start]; [call start];
waiterBlock(self, @[ expectReceive, expectComplete ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectReceive, expectComplete ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testConcurrentRPCsWithErrorsWithV2API { - (void)testConcurrentRPCsWithErrorsWithV2API {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
NSMutableArray *completeExpectations = [NSMutableArray array]; NSMutableArray *completeExpectations = [NSMutableArray array];
NSMutableArray *calls = [NSMutableArray array]; NSMutableArray *calls = [NSMutableArray array];
@ -805,7 +805,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
[call start]; [call start];
} }
waiterBlock(self, completeExpectations, GRPCInteropTestTimeoutDefault); waiterBlock(completeExpectations, GRPCInteropTestTimeoutDefault);
}); });
} }
@ -862,7 +862,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
} }
- (void)testPacketCoalescing { - (void)testPacketCoalescing {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"LargeUnary"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"LargeUnary"];
@ -901,13 +901,13 @@ static dispatch_once_t initGlobalInterceptorFactory;
} }
}]; }];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
[GRPCCall enableOpBatchLog:NO]; [GRPCCall enableOpBatchLog:NO];
}); });
} }
- (void)test4MBResponsesAreAccepted { - (void)test4MBResponsesAreAccepted {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"MaxResponseSize"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"MaxResponseSize"];
@ -927,12 +927,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
[expectation fulfill]; [expectation fulfill];
}]; }];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testResponsesOverMaxSizeFailWithActionableMessage { - (void)testResponsesOverMaxSizeFailWithActionableMessage {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = __weak XCTestExpectation *expectation =
[self expectationWithDescription:@"ResponseOverMaxSize"]; [self expectationWithDescription:@"ResponseOverMaxSize"];
@ -961,12 +961,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
@"Received message larger than max (4194305 vs. 4194304)"); @"Received message larger than max (4194305 vs. 4194304)");
[expectation fulfill]; [expectation fulfill];
}]; }];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testResponsesOver4MBAreAcceptedIfOptedIn { - (void)testResponsesOver4MBAreAcceptedIfOptedIn {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = __weak XCTestExpectation *expectation =
[self expectationWithDescription:@"HigherResponseSizeLimit"]; [self expectationWithDescription:@"HigherResponseSizeLimit"];
@ -987,13 +987,13 @@ static dispatch_once_t initGlobalInterceptorFactory;
[expectation fulfill]; [expectation fulfill];
}]; }];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
XCTAssertNil(callError, @"Finished with unexpected error: %@", callError); XCTAssertNil(callError, @"Finished with unexpected error: %@", callError);
}); });
} }
- (void)testClientStreamingRPC { - (void)testClientStreamingRPC {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"ClientStreaming"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"ClientStreaming"];
@ -1030,12 +1030,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
[expectation fulfill]; [expectation fulfill];
}]; }];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testServerStreamingRPC { - (void)testServerStreamingRPC {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"ServerStreaming"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"ServerStreaming"];
@ -1088,12 +1088,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
} }
}]; }];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testPingPongRPC { - (void)testPingPongRPC {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"PingPong"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"PingPong"];
@ -1155,12 +1155,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
[expectation fulfill]; [expectation fulfill];
} }
}]; }];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testPingPongRPCWithV2API { - (void)testPingPongRPCWithV2API {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"PingPongWithV2API"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"PingPongWithV2API"];
@ -1221,12 +1221,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
[call start]; [call start];
[call writeMessage:request]; [call writeMessage:request];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testPingPongRPCWithFlowControl { - (void)testPingPongRPCWithFlowControl {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"PingPongWithV2API"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"PingPongWithV2API"];
@ -1296,7 +1296,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
[call receiveNextMessage]; [call receiveNextMessage];
[call writeMessage:request]; [call writeMessage:request];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
assertBlock( assertBlock(
writeMessageCount == 4, writeMessageCount == 4,
[NSString stringWithFormat:@"writeMessageCount %@ not equal to 4", @(writeMessageCount)]); [NSString stringWithFormat:@"writeMessageCount %@ not equal to 4", @(writeMessageCount)]);
@ -1304,7 +1304,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
} }
- (void)testEmptyStreamRPC { - (void)testEmptyStreamRPC {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyStream"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyStream"];
__weak RMTTestService *weakService = service; __weak RMTTestService *weakService = service;
@ -1319,12 +1319,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
XCTAssert(done, @"Unexpected response: %@", response); XCTAssert(done, @"Unexpected response: %@", response);
[expectation fulfill]; [expectation fulfill];
}]; }];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testCancelAfterBeginRPC { - (void)testCancelAfterBeginRPC {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"CancelAfterBegin"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"CancelAfterBegin"];
@ -1350,12 +1350,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
[call cancel]; [call cancel];
XCTAssertEqual(call.state, GRXWriterStateFinished); XCTAssertEqual(call.state, GRXWriterStateFinished);
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testCancelAfterBeginRPCWithV2API { - (void)testCancelAfterBeginRPCWithV2API {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = __weak XCTestExpectation *expectation =
[self expectationWithDescription:@"CancelAfterBeginWithV2API"]; [self expectationWithDescription:@"CancelAfterBeginWithV2API"];
@ -1384,12 +1384,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
[call start]; [call start];
[call cancel]; [call cancel];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testCancelAfterFirstResponseRPC { - (void)testCancelAfterFirstResponseRPC {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = __weak XCTestExpectation *expectation =
[self expectationWithDescription:@"CancelAfterFirstResponse"]; [self expectationWithDescription:@"CancelAfterFirstResponse"];
@ -1426,12 +1426,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
} }
}]; }];
[call start]; [call start];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testCancelAfterFirstResponseRPCWithV2API { - (void)testCancelAfterFirstResponseRPCWithV2API {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *completionExpectation = __weak XCTestExpectation *completionExpectation =
[self expectationWithDescription:@"Call completed."]; [self expectationWithDescription:@"Call completed."];
@ -1476,13 +1476,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
weakCall = call; weakCall = call;
[call start]; [call start];
[call writeMessage:request]; [call writeMessage:request];
waiterBlock(self, @[ completionExpectation, responseExpectation ], waiterBlock(@[ completionExpectation, responseExpectation ], GRPCInteropTestTimeoutDefault);
GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testCancelAfterFirstRequestWithV2API { - (void)testCancelAfterFirstRequestWithV2API {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *completionExpectation = __weak XCTestExpectation *completionExpectation =
[self expectationWithDescription:@"Call completed."]; [self expectationWithDescription:@"Call completed."];
@ -1519,12 +1518,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
[call start]; [call start];
[call writeMessage:request]; [call writeMessage:request];
[call cancel]; [call cancel];
waiterBlock(self, @[ completionExpectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ completionExpectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testRPCAfterClosingOpenConnections { - (void)testRPCAfterClosingOpenConnections {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = __weak XCTestExpectation *expectation =
[self expectationWithDescription:@"RPC after closing connection"]; [self expectationWithDescription:@"RPC after closing connection"];
@ -1556,7 +1555,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
}]; }];
}]; }];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
@ -1567,7 +1566,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
return; return;
} }
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"LargeUnary"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"LargeUnary"];
@ -1596,12 +1595,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
[expectation fulfill]; [expectation fulfill];
}]; }];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testKeepaliveWithV2API { - (void)testKeepaliveWithV2API {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
if ([[self class] transport] == gGRPCCoreCronetID) { if ([[self class] transport] == gGRPCCoreCronetID) {
// Cronet does not support keepalive // Cronet does not support keepalive
@ -1644,13 +1643,13 @@ static dispatch_once_t initGlobalInterceptorFactory;
[call writeMessage:request]; [call writeMessage:request];
[call start]; [call start];
waiterBlock(self, @[ expectation ], kTestTimeout); waiterBlock(@[ expectation ], kTestTimeout);
[call finish]; [call finish];
}); });
} }
- (void)testDefaultInterceptor { - (void)testDefaultInterceptor {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = __weak XCTestExpectation *expectation =
[self expectationWithDescription:@"testDefaultInterceptor"]; [self expectationWithDescription:@"testDefaultInterceptor"];
@ -1717,12 +1716,12 @@ static dispatch_once_t initGlobalInterceptorFactory;
[call start]; [call start];
[call writeMessage:request]; [call writeMessage:request];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testLoggingInterceptor { - (void)testLoggingInterceptor {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = __weak XCTestExpectation *expectation =
[self expectationWithDescription:@"testLoggingInterceptor"]; [self expectationWithDescription:@"testLoggingInterceptor"];
@ -1843,7 +1842,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
[call receiveNextMessage]; [call receiveNextMessage];
[call writeMessage:request]; [call writeMessage:request];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
assertBlock(startCount == 1, [NSString stringWithFormat:@"%@", @(startCount)]); assertBlock(startCount == 1, [NSString stringWithFormat:@"%@", @(startCount)]);
assertBlock(writeDataCount == 4, [NSString stringWithFormat:@"%@", @(writeDataCount)]); assertBlock(writeDataCount == 4, [NSString stringWithFormat:@"%@", @(writeDataCount)]);
@ -1862,7 +1861,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
// Chain a default interceptor and a hook interceptor which, after one write, cancels the call // Chain a default interceptor and a hook interceptor which, after one write, cancels the call
// under the hood but forward further data to the user. // under the hood but forward further data to the user.
- (void)testHijackingInterceptor { - (void)testHijackingInterceptor {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
NSUInteger kCancelAfterWrites = 1; NSUInteger kCancelAfterWrites = 1;
__weak XCTestExpectation *expectUserCallComplete = __weak XCTestExpectation *expectUserCallComplete =
@ -1990,7 +1989,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
[call receiveNextMessage]; [call receiveNextMessage];
[call writeMessage:request]; [call writeMessage:request];
waiterBlock(self, @[ expectUserCallComplete ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectUserCallComplete ], GRPCInteropTestTimeoutDefault);
assertBlock(startCount == 1, [NSString stringWithFormat:@"%@", @(startCount)]); assertBlock(startCount == 1, [NSString stringWithFormat:@"%@", @(startCount)]);
assertBlock(writeDataCount == 4, [NSString stringWithFormat:@"%@", @(writeDataCount)]); assertBlock(writeDataCount == 4, [NSString stringWithFormat:@"%@", @(writeDataCount)]);
assertBlock(finishCount == 1, [NSString stringWithFormat:@"%@", @(finishCount)]); assertBlock(finishCount == 1, [NSString stringWithFormat:@"%@", @(finishCount)]);
@ -2002,7 +2001,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
} }
- (void)testGlobalInterceptor { - (void)testGlobalInterceptor {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = __weak XCTestExpectation *expectation =
[self expectationWithDescription:@"testGlobalInterceptor"]; [self expectationWithDescription:@"testGlobalInterceptor"];
@ -2112,7 +2111,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
[call start]; [call start];
[call receiveNextMessage]; [call receiveNextMessage];
[call writeMessage:request]; [call writeMessage:request];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
assertBlock(startCount == 1, [NSString stringWithFormat:@"%@", @(startCount)]); assertBlock(startCount == 1, [NSString stringWithFormat:@"%@", @(startCount)]);
assertBlock(writeDataCount == 4, [NSString stringWithFormat:@"%@", @(writeDataCount)]); assertBlock(writeDataCount == 4, [NSString stringWithFormat:@"%@", @(writeDataCount)]);
@ -2149,7 +2148,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
} }
- (void)testInterceptorAndGlobalInterceptor { - (void)testInterceptorAndGlobalInterceptor {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]]; RMTTestService *service = [RMTTestService serviceWithHost:[[self class] host]];
__weak XCTestExpectation *expectation = __weak XCTestExpectation *expectation =
[self expectationWithDescription:@"testInterceptorAndGlobalInterceptor"]; [self expectationWithDescription:@"testInterceptorAndGlobalInterceptor"];
@ -2309,7 +2308,7 @@ static dispatch_once_t initGlobalInterceptorFactory;
[call receiveNextMessage]; [call receiveNextMessage];
[call writeMessage:request]; [call writeMessage:request];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
assertBlock(startCount == 1, [NSString stringWithFormat:@"%@", @(startCount)]); assertBlock(startCount == 1, [NSString stringWithFormat:@"%@", @(startCount)]);
assertBlock(writeDataCount == 4, [NSString stringWithFormat:@"%@", @(writeDataCount)]); assertBlock(writeDataCount == 4, [NSString stringWithFormat:@"%@", @(writeDataCount)]);
assertBlock(finishCount == 1, [NSString stringWithFormat:@"%@", @(finishCount)]); assertBlock(finishCount == 1, [NSString stringWithFormat:@"%@", @(finishCount)]);

@ -83,7 +83,7 @@ static GRPCProtoMethod *kUnaryCallMethod;
} }
- (void)testMetadataForV2Call { - (void)testMetadataForV2Call {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."]; XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."];
RMTSimpleRequest *request = [RMTSimpleRequest message]; RMTSimpleRequest *request = [RMTSimpleRequest message];
@ -131,12 +131,12 @@ static GRPCProtoMethod *kUnaryCallMethod;
[call writeData:[request data]]; [call writeData:[request data]];
[call finish]; [call finish];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testMetadataForV1Call { - (void)testMetadataForV1Call {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."]; XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."];
RMTSimpleRequest *request = [RMTSimpleRequest message]; RMTSimpleRequest *request = [RMTSimpleRequest message];
@ -178,12 +178,12 @@ static GRPCProtoMethod *kUnaryCallMethod;
[call startWithWriteable:responsesWriteable]; [call startWithWriteable:responsesWriteable];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }
- (void)testErrorDebugInformation { - (void)testErrorDebugInformation {
GRPCTestRunWithFlakeRepeats(^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) { GRPCTestRunWithFlakeRepeats(self, ^(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock) {
XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."]; XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."];
RMTSimpleRequest *request = [RMTSimpleRequest message]; RMTSimpleRequest *request = [RMTSimpleRequest message];
@ -223,7 +223,7 @@ static GRPCProtoMethod *kUnaryCallMethod;
[call startWithWriteable:responsesWriteable]; [call startWithWriteable:responsesWriteable];
waiterBlock(self, @[ expectation ], GRPCInteropTestTimeoutDefault); waiterBlock(@[ expectation ], GRPCInteropTestTimeoutDefault);
}); });
} }

Loading…
Cancel
Save