Debian Codegraph @

src/objective-c/tests/Common/TestUtils.h

raw
1 /*
2 *
3 * Copyright 2019 gRPC authors.
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 *
17 */
18
19 #import <Foundation/Foundation.h>
20 #import <XCTest/XCTest.h>
21
22 NS_ASSUME_NONNULL_BEGIN
23
24 /* Default test timeout in seconds for interopt test. */
25 FOUNDATION_EXPORT const NSTimeInterval GRPCInteropTestTimeoutDefault;
26
27 // Block typedef for waiting for a target group of expectations via XCTWaiter.
28 typedef void (^GRPCTestWaiter)(NSArray<XCTestExpectation *> *expectations, NSTimeInterval timeout);
29
30 // Block typedef for asserting a given expression value with optional retry.
31 typedef void (^GRPCTestAssert)(BOOL expressionValue, NSString *message);
32
33 // Block typedef for a test run. Test run should call waiter to wait for a group of expectations
34 // with timeout. Test run can also optionally invoke assertBlock to report assertion failure.
35 // Failed assertion will be retried up to maximum retry.
36 typedef void (^GRPCTestRunBlock)(GRPCTestWaiter waiterBlock, GRPCTestAssert assertBlock);
37
38 /**
39 * Common utility to fetch plain text local interop server address.
40 *
41 * @return Interop test server address including host and port.
42 */
43 FOUNDATION_EXPORT NSString *GRPCGetLocalInteropTestServerAddressPlainText(void);
44
45 /**
46 * Common utility to fetch ssl local interop server address.
47 *
48 * @return Interop test server address including host and port.
49 */
50 FOUNDATION_EXPORT NSString *GRPCGetLocalInteropTestServerAddressSSL(void);
51
52 /**
53 * Common utility to fetch remote interop test server address.
54 *
55 * @return Interop test server address including host and port.
56 */
57 FOUNDATION_EXPORT NSString *GRPCGetRemoteInteropTestServerAddress(void);
58
59 /**
60 * Common utility to print interop server address information to console via NSLog.
61 */
62 FOUNDATION_EXPORT void GRPCPrintInteropTestServerDebugInfo(void);
63
64 /**
65 * Common utility to run a test block until success, up to predefined number of repeats.
66 * @param testCase Associated test case run for reporting test failures.
67 * @param testBlock Target test block to be invoked by the utility function. The block will be
68 * invoked synchronously before the function returns.
69 * @return YES if test run succeeded within the repeat limit. NO otherwise.
70 */
71 FOUNDATION_EXPORT BOOL GRPCTestRunWithFlakeRepeats(XCTestCase *testCase,
72 GRPCTestRunBlock testBlock);
73
74 /**
75 * Common utility to reset gRPC call's active connections.
76 */
77 FOUNDATION_EXPORT void GRPCResetCallConnections(void);
78
79 NS_ASSUME_NONNULL_END