[gRPC/iOS] Introduce common test util for reading interop server addr (#29774)

pull/29794/head
Denny C. Dai 3 years ago committed by GitHub
parent 887a605940
commit 62032f6838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      src/objective-c/tests/BUILD
  2. 20
      src/objective-c/tests/Common/Common.podspec
  3. 0
      src/objective-c/tests/Common/TestBase.h
  4. 0
      src/objective-c/tests/Common/TestBase.m
  5. 44
      src/objective-c/tests/Common/TestUtils.h
  6. 51
      src/objective-c/tests/Common/TestUtils.m
  7. 2
      src/objective-c/tests/InteropTests/InteropTests.h
  8. 2
      src/objective-c/tests/MacTests/StressTests.h
  9. 2
      src/objective-c/tests/PerfTests/PerfTests.h
  10. 1
      src/objective-c/tests/Podfile
  11. 14
      src/objective-c/tests/Tests.xcodeproj/project.pbxproj
  12. 17
      src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/UnitTests.xcscheme
  13. 37
      src/objective-c/tests/UnitTests/APIv2Tests.m

@ -60,7 +60,12 @@ apple_resource_bundle(
# TestConfigs is added to each grpc_objc_testing_library's deps
grpc_objc_testing_library(
name = "TestConfigs",
hdrs = ["version.h"],
srcs = glob([
"Common/**/*.m",
]),
hdrs = glob([
"Common/**/*.h",
]) + ["version.h"],
data = [":TestCertificates"],
defines = [
"DEBUG=1",
@ -102,7 +107,6 @@ grpc_objc_testing_library(
hdrs = ["InteropTests/InteropTests.h"],
deps = [
":InteropTestsBlockCallbacks-lib",
":TestBase-lib",
],
)
@ -177,15 +181,6 @@ grpc_objc_testing_library(
"MacTests/*.m",
]),
hdrs = ["MacTests/StressTests.h"],
deps = [
":TestBase-lib",
],
)
grpc_objc_testing_library(
name = "TestBase-lib",
srcs = ["TestBase.m"],
hdrs = ["TestBase.h"],
)
ios_unit_test(

@ -0,0 +1,20 @@
Pod::Spec.new do |s|
s.name = 'Common'
s.version = "0.0.1"
s.license = "Apache License, Version 2.0"
s.authors = { 'gRPC contributors' => 'grpc-io@googlegroups.com' }
s.homepage = "https://grpc.io/"
s.summary = "Shared common test utils"
s.source = { :git => 'https://github.com/grpc/grpc.git' }
s.ios.deployment_target = '9.0'
s.osx.deployment_target = '10.10'
s.tvos.deployment_target = '10.0'
s.watchos.deployment_target = '4.0'
s.framework = 'XCTest'
s.dependency "gRPC-ProtoRPC"
s.source_files = '**/*.{m}'
s.public_header_files = '**/*.{h}'
end

@ -0,0 +1,44 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Common utility to fetch plain text local interop server address.
*
* @return Interop test server address including host and port.
*/
FOUNDATION_EXPORT NSString *GRPCGetLocalInteropTestServerAddressPlainText(void);
/**
* Common utility to fetch ssl local interop server address.
*
* @return Interop test server address including host and port.
*/
FOUNDATION_EXPORT NSString *GRPCGetLocalInteropTestServerAddressSSL(void);
/**
* Common utility to fetch remote interop test server address.
*
* @return Interop test server address including host and port.
*/
FOUNDATION_EXPORT NSString *GRPCGetRemoteInteropTestServerAddress(void);
NS_ASSUME_NONNULL_END

@ -0,0 +1,51 @@
/**
* Copyright 2022 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "TestUtils.h"
// Utility macro to stringize preprocessor defines
#define NSStringize_helper(x) #x
#define NSStringize(x) @NSStringize_helper(x)
NSString *GRPCGetLocalInteropTestServerAddressPlainText() {
static NSString *address;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
address =
[NSProcessInfo processInfo].environment[@"HOST_PORT_LOCAL"] ?: NSStringize(HOST_PORT_LOCAL);
});
return address;
}
NSString *GRPCGetLocalInteropTestServerAddressSSL() {
static NSString *address;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
address = [NSProcessInfo processInfo].environment[@"HOST_PORT_LOCALSSL"]
?: NSStringize(HOST_PORT_LOCALSSL);
});
return address;
}
NSString *GRPCGetRemoteInteropTestServerAddress() {
static NSString *address;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
address = [NSProcessInfo processInfo].environment[@"HOST_PORT_REMOTE"]
?: NSStringize(HOST_PORT_REMOTE);
});
return address;
}

@ -18,7 +18,7 @@
#import <XCTest/XCTest.h>
#import "../TestBase.h"
#import "../Common/TestBase.h"
/**
* Implements tests as described here:

@ -18,7 +18,7 @@
#import <XCTest/XCTest.h>
#import "../TestBase.h"
#import "../Common/TestBase.h"
@interface StressTests : TestBase

@ -17,7 +17,7 @@
*/
#import <XCTest/XCTest.h>
#import "../TestBase.h"
#import "../Common/TestBase.h"
/**
* This is an abstract class that needs to be subclassed. See |+host|.

@ -19,6 +19,7 @@ def grpc_deps
pod 'gRPC-RxLibrary', :path => GRPC_LOCAL_SRC
pod 'gRPC-ProtoRPC', :path => GRPC_LOCAL_SRC, :inhibit_warnings => true
pod 'RemoteTest', :path => "RemoteTestClient", :inhibit_warnings => true
pod 'Common', :path => "Common"
end
target 'TvTests' do

@ -52,11 +52,6 @@
ABCB3EEA22F23BF500F0FECE /* APIv2Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E7F487F227782C1006656AD /* APIv2Tests.m */; };
ABCB3EEB22F23BF500F0FECE /* NSErrorUnitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E0282E8215AA697007AC99D /* NSErrorUnitTests.m */; };
B071230B22669EED004B64A1 /* StressTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B071230A22669EED004B64A1 /* StressTests.m */; };
B098FC622331B7EA00029C0E /* TestBase.m in Sources */ = {isa = PBXBuildFile; fileRef = B0C461E02331AC5C004E17DA /* TestBase.m */; };
B098FC632331B7FA00029C0E /* TestBase.m in Sources */ = {isa = PBXBuildFile; fileRef = B0C461E02331AC5C004E17DA /* TestBase.m */; };
B098FC642331B80500029C0E /* TestBase.m in Sources */ = {isa = PBXBuildFile; fileRef = B0C461E02331AC5C004E17DA /* TestBase.m */; };
B098FC652331B82000029C0E /* TestBase.m in Sources */ = {isa = PBXBuildFile; fileRef = B0C461E02331AC5C004E17DA /* TestBase.m */; };
B098FC662331B83900029C0E /* TestBase.m in Sources */ = {isa = PBXBuildFile; fileRef = B0C461E02331AC5C004E17DA /* TestBase.m */; };
B0A420C523299D2200D95F2A /* TestCertificates.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 63E240CF1B6C63DC005F3B0E /* TestCertificates.bundle */; };
B0A420C623299D2D00D95F2A /* ConfigureCronet.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E3F1487227918AA007C6D90 /* ConfigureCronet.m */; };
B0BB3F08225E7ABA008DA580 /* NSErrorUnitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E0282E8215AA697007AC99D /* NSErrorUnitTests.m */; };
@ -186,8 +181,6 @@
B071230A22669EED004B64A1 /* StressTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = StressTests.m; sourceTree = "<group>"; };
B0BB3EF7225E795F008DA580 /* MacTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MacTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
B0BB3EFB225E795F008DA580 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B0C461DF2331AC3F004E17DA /* TestBase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestBase.h; sourceTree = "<group>"; };
B0C461E02331AC5C004E17DA /* TestBase.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TestBase.m; sourceTree = "<group>"; };
B0C5FC172267C77200F192BE /* StressTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StressTests.h; sourceTree = "<group>"; };
B0D39B992266F3CB00A4078D /* StressTestsSSL.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = StressTestsSSL.m; sourceTree = "<group>"; };
B0D39B9B2266FF9800A4078D /* StressTestsCleartext.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = StressTestsCleartext.m; sourceTree = "<group>"; };
@ -492,8 +485,6 @@
5E3F148A227918C4007C6D90 /* ConfigureCronet.h */,
5E3F1487227918AA007C6D90 /* ConfigureCronet.m */,
5EAFE8271F8EFB87007F2189 /* version.h */,
B0C461E02331AC5C004E17DA /* TestBase.m */,
B0C461DF2331AC3F004E17DA /* TestBase.h */,
635697D71B14FC11007A7283 /* Supporting Files */,
);
name = Tests;
@ -1051,7 +1042,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B098FC652331B82000029C0E /* TestBase.m in Sources */,
5E3F14852278BF5D007C6D90 /* InteropTestsBlockCallbacks.m in Sources */,
5E3F148D22792856007C6D90 /* ConfigureCronet.m in Sources */,
5E08D07023021E3B006D76EA /* InteropTestsMultipleChannels.m in Sources */,
@ -1067,7 +1057,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B098FC642331B80500029C0E /* TestBase.m in Sources */,
5E3F14842278B461007C6D90 /* InteropTestsBlockCallbacks.m in Sources */,
5E7F488922778B04006656AD /* InteropTestsRemote.m in Sources */,
5EA477042273617B000F72FC /* InteropTestsLocalCleartext.m in Sources */,
@ -1080,7 +1069,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B098FC662331B83900029C0E /* TestBase.m in Sources */,
ABCB3EEA22F23BF500F0FECE /* APIv2Tests.m in Sources */,
ABCB3EE822F23BEF00F0FECE /* InteropTestsBlockCallbacks.m in Sources */,
ABCB3EE422F23BEF00F0FECE /* InteropTestsRemote.m in Sources */,
@ -1096,7 +1084,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B098FC632331B7FA00029C0E /* TestBase.m in Sources */,
B0BB3F08225E7ABA008DA580 /* NSErrorUnitTests.m in Sources */,
5E7F488D22778C85006656AD /* InteropTestsLocalSSL.m in Sources */,
5E7F488E22778C87006656AD /* InteropTestsLocalCleartext.m in Sources */,
@ -1115,7 +1102,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B098FC622331B7EA00029C0E /* TestBase.m in Sources */,
B0A420C623299D2D00D95F2A /* ConfigureCronet.m in Sources */,
B0F2D0C4232991CC008C2575 /* PerfTestsBlockCallbacks.h in Sources */,
B0F2D0C5232991CC008C2575 /* PerfTestsBlockCallbacks.m in Sources */,

@ -39,8 +39,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Test"
@ -62,11 +60,26 @@
</BuildableReference>
</MacroExpansion>
<EnvironmentVariables>
<EnvironmentVariable
key = "HOST_PORT_LOCAL"
value = "localhost:5050"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "HOST_PORT_REMOTE"
value = "grpc-test.sandbox.googleapis.com"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "GRPC_CFSTREAM_RUN_LOOP"
value = "1"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "HOST_PORT_LOCALSSL"
value = "localhost:5051"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction

@ -24,15 +24,9 @@
#include <grpc/grpc.h>
#include <grpc/support/port_platform.h>
#import "../Common/TestUtils.h"
#import "../version.h"
// The server address is derived from preprocessor macro, which is
// in turn derived from environment variable of the same name.
#define NSStringize_helper(x) #x
#define NSStringize(x) @NSStringize_helper(x)
static NSString *const kHostAddress = NSStringize(HOST_PORT_LOCAL);
static NSString *const kRemoteSSLHost = NSStringize(HOST_PORT_REMOTE);
// Package and service name of test server
static NSString *const kPackage = @"grpc.testing";
static NSString *const kService = @"TestService";
@ -164,7 +158,7 @@ static const NSTimeInterval kInvertedTimeout = 2;
request.fillOauthScope = YES;
GRPCRequestOptions *callRequest =
[[GRPCRequestOptions alloc] initWithHost:(NSString *)kRemoteSSLHost
[[GRPCRequestOptions alloc] initWithHost:GRPCGetRemoteInteropTestServerAddress()
path:kUnaryCallMethod.HTTPPath
safety:GRPCCallSafetyDefault];
__block NSDictionary *init_md;
@ -210,9 +204,10 @@ static const NSTimeInterval kInvertedTimeout = 2;
__weak XCTestExpectation *recvInitialMd =
[self expectationWithDescription:@"Did not receive initial md."];
GRPCRequestOptions *request = [[GRPCRequestOptions alloc] initWithHost:kHostAddress
path:kEmptyCallMethod.HTTPPath
safety:GRPCCallSafetyDefault];
GRPCRequestOptions *request =
[[GRPCRequestOptions alloc] initWithHost:GRPCGetLocalInteropTestServerAddressPlainText()
path:kEmptyCallMethod.HTTPPath
safety:GRPCCallSafetyDefault];
NSDictionary *headers =
[NSDictionary dictionaryWithObjectsAndKeys:@"", @"x-grpc-test-echo-useragent", nil];
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
@ -286,7 +281,7 @@ static const NSTimeInterval kInvertedTimeout = 2;
__weak XCTestExpectation *completion = [self expectationWithDescription:@"RPC completed."];
GRPCRequestOptions *requestOptions =
[[GRPCRequestOptions alloc] initWithHost:kHostAddress
[[GRPCRequestOptions alloc] initWithHost:GRPCGetLocalInteropTestServerAddressPlainText()
path:kEmptyCallMethod.HTTPPath
safety:GRPCCallSafetyDefault];
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
@ -313,7 +308,7 @@ static const NSTimeInterval kInvertedTimeout = 2;
__weak XCTestExpectation *completion = [self expectationWithDescription:@"RPC completed."];
GRPCRequestOptions *requestOptions =
[[GRPCRequestOptions alloc] initWithHost:kHostAddress
[[GRPCRequestOptions alloc] initWithHost:GRPCGetLocalInteropTestServerAddressPlainText()
path:kUnaryCallMethod.HTTPPath
safety:GRPCCallSafetyDefault];
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
@ -352,7 +347,7 @@ static const NSTimeInterval kInvertedTimeout = 2;
options.timeout = 0.001;
options.transportType = GRPCTransportTypeInsecure;
GRPCRequestOptions *requestOptions =
[[GRPCRequestOptions alloc] initWithHost:kHostAddress
[[GRPCRequestOptions alloc] initWithHost:GRPCGetLocalInteropTestServerAddressPlainText()
path:kFullDuplexCallMethod.HTTPPath
safety:GRPCCallSafetyDefault];
@ -435,7 +430,7 @@ static const NSTimeInterval kInvertedTimeout = 2;
request.responseSize = kSimpleDataLength;
request.payload.body = [NSMutableData dataWithLength:kSimpleDataLength];
GRPCRequestOptions *requestOptions =
[[GRPCRequestOptions alloc] initWithHost:kHostAddress
[[GRPCRequestOptions alloc] initWithHost:GRPCGetLocalInteropTestServerAddressPlainText()
path:kUnaryCallMethod.HTTPPath
safety:GRPCCallSafetyDefault];
@ -477,7 +472,7 @@ static const NSTimeInterval kInvertedTimeout = 2;
request.payload.body = [NSMutableData dataWithLength:kSimpleDataLength];
GRPCRequestOptions *callRequest =
[[GRPCRequestOptions alloc] initWithHost:(NSString *)kHostAddress
[[GRPCRequestOptions alloc] initWithHost:GRPCGetLocalInteropTestServerAddressPlainText()
path:kUnaryCallMethod.HTTPPath
safety:GRPCCallSafetyDefault];
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
@ -519,7 +514,7 @@ static const NSTimeInterval kInvertedTimeout = 2;
request.payload.body = [NSMutableData dataWithLength:kSimpleDataLength];
GRPCRequestOptions *callRequest =
[[GRPCRequestOptions alloc] initWithHost:(NSString *)kHostAddress
[[GRPCRequestOptions alloc] initWithHost:GRPCGetLocalInteropTestServerAddressPlainText()
path:kUnaryCallMethod.HTTPPath
safety:GRPCCallSafetyDefault];
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
@ -580,7 +575,7 @@ static const NSTimeInterval kInvertedTimeout = 2;
request.payload.body = [NSMutableData dataWithLength:kSimpleDataLength];
GRPCRequestOptions *callRequest =
[[GRPCRequestOptions alloc] initWithHost:(NSString *)kHostAddress
[[GRPCRequestOptions alloc] initWithHost:GRPCGetLocalInteropTestServerAddressPlainText()
path:kFullDuplexCallMethod.HTTPPath
safety:GRPCCallSafetyDefault];
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
@ -623,7 +618,7 @@ static const NSTimeInterval kInvertedTimeout = 2;
request.payload.body = [NSMutableData dataWithLength:kSimpleDataLength];
GRPCRequestOptions *callRequest =
[[GRPCRequestOptions alloc] initWithHost:(NSString *)kHostAddress
[[GRPCRequestOptions alloc] initWithHost:GRPCGetLocalInteropTestServerAddressPlainText()
path:kUnaryCallMethod.HTTPPath
safety:GRPCCallSafetyDefault];
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
@ -664,7 +659,7 @@ static const NSTimeInterval kInvertedTimeout = 2;
request.payload.body = [NSMutableData dataWithLength:kSimpleDataLength];
GRPCRequestOptions *callRequest =
[[GRPCRequestOptions alloc] initWithHost:(NSString *)kHostAddress
[[GRPCRequestOptions alloc] initWithHost:GRPCGetLocalInteropTestServerAddressPlainText()
path:kUnaryCallMethod.HTTPPath
safety:GRPCCallSafetyDefault];
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
@ -696,7 +691,7 @@ static const NSTimeInterval kInvertedTimeout = 2;
__weak XCTestExpectation *completion = [self expectationWithDescription:@"RPC completed."];
GRPCRequestOptions *requestOptions =
[[GRPCRequestOptions alloc] initWithHost:kHostAddress
[[GRPCRequestOptions alloc] initWithHost:GRPCGetLocalInteropTestServerAddressPlainText()
path:kUnaryCallMethod.HTTPPath
safety:GRPCCallSafetyDefault];
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];

Loading…
Cancel
Save