Skip to content

Commit

Permalink
[gRPC/iOS] Introduce common test util for reading interop server addr (
Browse files Browse the repository at this point in the history
  • Loading branch information
dennycd authored May 26, 2022
1 parent 887a605 commit 62032f6
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 51 deletions.
17 changes: 6 additions & 11 deletions src/objective-c/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -102,7 +107,6 @@ grpc_objc_testing_library(
hdrs = ["InteropTests/InteropTests.h"],
deps = [
":InteropTestsBlockCallbacks-lib",
":TestBase-lib",
],
)

Expand Down Expand Up @@ -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(
Expand Down
20 changes: 20 additions & 0 deletions src/objective-c/tests/Common/Common.podspec
Original file line number Diff line number Diff line change
@@ -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' => '[email protected]' }
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
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions src/objective-c/tests/Common/TestUtils.h
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions src/objective-c/tests/Common/TestUtils.m
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion src/objective-c/tests/InteropTests/InteropTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#import <XCTest/XCTest.h>

#import "../TestBase.h"
#import "../Common/TestBase.h"

/**
* Implements tests as described here:
Expand Down
2 changes: 1 addition & 1 deletion src/objective-c/tests/MacTests/StressTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#import <XCTest/XCTest.h>

#import "../TestBase.h"
#import "../Common/TestBase.h"

@interface StressTests : TestBase

Expand Down
2 changes: 1 addition & 1 deletion src/objective-c/tests/PerfTests/PerfTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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|.
Expand Down
1 change: 1 addition & 0 deletions src/objective-c/tests/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions src/objective-c/tests/Tests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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>"; };
Expand Down Expand Up @@ -492,8 +485,6 @@
5E3F148A227918C4007C6D90 /* ConfigureCronet.h */,
5E3F1487227918AA007C6D90 /* ConfigureCronet.m */,
5EAFE8271F8EFB87007F2189 /* version.h */,
B0C461E02331AC5C004E17DA /* TestBase.m */,
B0C461DF2331AC3F004E17DA /* TestBase.h */,
635697D71B14FC11007A7283 /* Supporting Files */,
);
name = Tests;
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand All @@ -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 */,
Expand All @@ -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 */,
Expand All @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Test"
Expand All @@ -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
Expand Down
Loading

0 comments on commit 62032f6

Please sign in to comment.