Fix Cronet multiple initialization problem

pull/18919/head
Muxi Yan 6 years ago
parent 2e8e7e4838
commit d6c98bf82e
  1. 10
      src/objective-c/tests/CronetTests/CoreCronetEnd2EndTests.mm
  2. 13
      src/objective-c/tests/CronetTests/CronetUnitTests.mm
  3. 4
      src/objective-c/tests/CronetTests/InteropTestsRemoteWithCronet.m
  4. 34
      src/objective-c/tests/EnableCronet.h
  5. 38
      src/objective-c/tests/EnableCronet.m
  6. 5
      src/objective-c/tests/InteropTests/InteropTests.h
  7. 14
      src/objective-c/tests/InteropTests/InteropTests.m
  8. 8
      src/objective-c/tests/Tests.xcodeproj/project.pbxproj
  9. 5
      src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/CronetTests.xcscheme

@ -49,6 +49,8 @@
#import <Cronet/Cronet.h>
#include <grpc/grpc_cronet.h>
#import "../EnableCronet.h"
typedef struct fullstack_secure_fixture_data {
char *localaddr;
} fullstack_secure_fixture_data;
@ -176,13 +178,7 @@ static char *roots_filename;
grpc_init();
[Cronet setHttp2Enabled:YES];
[Cronet enableTestCertVerifierForTesting];
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];
NSLog(@"Documents directory: %@", url);
[Cronet start];
[Cronet startNetLogToFile:@"cronet_netlog.json" logBytes:YES];
enableCronet();
}
// The tearDown() function is run after all test cases finish running

@ -20,6 +20,8 @@
#import <netinet/in.h>
#import <sys/socket.h>
#import "../EnableCronet.h"
#import <Cronet/Cronet.h>
#import <grpc/grpc.h>
#import <grpc/grpc_cronet.h>
@ -61,16 +63,7 @@ static void drain_cq(grpc_completion_queue *cq) {
grpc_test_init(1, argv);
grpc_init();
[Cronet setHttp2Enabled:YES];
[Cronet setSslKeyLogFileName:@"Documents/key"];
[Cronet enableTestCertVerifierForTesting];
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];
NSLog(@"Documents directory: %@", url);
[Cronet start];
[Cronet startNetLogToFile:@"Documents/cronet_netlog.json" logBytes:YES];
enableCronet();
init_ssl();
}

@ -44,6 +44,10 @@ static int32_t kRemoteInteropServerOverhead = 12;
return kRemoteSSLHost;
}
+ (BOOL)useCronet {
return YES;
}
- (int32_t)encodingOverhead {
return kRemoteInteropServerOverhead; // bytes
}

@ -0,0 +1,34 @@
/*
*
* 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.
*
*/
#ifdef GRPC_COMPILE_WITH_CRONET
#ifdef __cplusplus
extern "C" {
#endif
/**
* Enable Cronet for once.
*/
void enableCronet();
#ifdef __cplusplus
}
#endif
#endif

@ -0,0 +1,38 @@
/*
*
* 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.
*
*/
#ifdef GRPC_COMPILE_WITH_CRONET
#import <Cronet/Cronet.h>
#import "EnableCronet.h"
void enableCronet(void) {
static dispatch_once_t enableCronet;
dispatch_once(&enableCronet, ^{
[Cronet setHttp2Enabled:YES];
[Cronet setSslKeyLogFileName:@"Documents/key"];
[Cronet enableTestCertVerifierForTesting];
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];
NSLog(@"Documents directory: %@", url);
[Cronet start];
[Cronet startNetLogToFile:@"cronet_netlog.json" logBytes:YES];
});
}
#endif

@ -59,4 +59,9 @@
*/
+ (NSString *)hostNameOverride;
/**
* Whether to use Cronet for all the v1 API tests in the test suite.
*/
+ (BOOL)useCronet;
@end

@ -37,6 +37,7 @@
#import <grpc/support/log.h>
#import "InteropTestsBlockCallbacks.h"
#import "../enableCronet.h"
#define TEST_TIMEOUT 32
@ -107,16 +108,17 @@ BOOL isRemoteInteropTest(NSString *host) {
return nil;
}
+ (BOOL)useCronet {
return NO;
}
+ (void)setUp {
NSLog(@"InteropTest Started, class: %@", [[self class] description]);
#ifdef GRPC_COMPILE_WITH_CRONET
static dispatch_once_t *enableCronet;
dispatch_once(enableCronet, ^{
// Cronet setup
[Cronet setHttp2Enabled:YES];
[Cronet start];
enableCronet();
if ([self useCronet]) {
[GRPCCall useCronetWithEngine:[Cronet getGlobalEngine]];
});
}
#endif
#ifdef GRPC_CFSTREAM
setenv(kCFStreamVarName, "1", 1);

@ -11,6 +11,8 @@
5E3F14842278B461007C6D90 /* InteropTestsBlockCallbacks.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E3F14832278B461007C6D90 /* InteropTestsBlockCallbacks.m */; };
5E3F14852278BF5D007C6D90 /* InteropTestsBlockCallbacks.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E3F14832278B461007C6D90 /* InteropTestsBlockCallbacks.m */; };
5E3F14862278BFFF007C6D90 /* InteropTestsBlockCallbacks.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E3F14832278B461007C6D90 /* InteropTestsBlockCallbacks.m */; };
5E3F148D22792856007C6D90 /* EnableCronet.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E3F1487227918AA007C6D90 /* EnableCronet.m */; };
5E3F148E22792AF5007C6D90 /* EnableCronet.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E3F1487227918AA007C6D90 /* EnableCronet.m */; };
5E7F486422775B37006656AD /* InteropTestsRemoteWithCronet.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EE84BF31D4717E40050C6CC /* InteropTestsRemoteWithCronet.m */; };
5E7F486522775B41006656AD /* CronetUnitTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5EAD6D261E27047400002378 /* CronetUnitTests.mm */; };
5E7F486E22778086006656AD /* CoreCronetEnd2EndTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5E7F486D22778086006656AD /* CoreCronetEnd2EndTests.mm */; };
@ -92,6 +94,8 @@
5E0282E8215AA697007AC99D /* NSErrorUnitTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NSErrorUnitTests.m; sourceTree = "<group>"; };
5E3F14822278B42D007C6D90 /* InteropTestsBlockCallbacks.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InteropTestsBlockCallbacks.h; sourceTree = "<group>"; };
5E3F14832278B461007C6D90 /* InteropTestsBlockCallbacks.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InteropTestsBlockCallbacks.m; sourceTree = "<group>"; };
5E3F1487227918AA007C6D90 /* EnableCronet.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EnableCronet.m; sourceTree = "<group>"; };
5E3F148A227918C4007C6D90 /* EnableCronet.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EnableCronet.h; sourceTree = "<group>"; };
5E7F485922775B15006656AD /* CronetTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CronetTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
5E7F486622776AD8006656AD /* Cronet.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cronet.framework; path = Pods/CronetFramework/Cronet.framework; sourceTree = "<group>"; };
5E7F486D22778086006656AD /* CoreCronetEnd2EndTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CoreCronetEnd2EndTests.mm; sourceTree = "<group>"; };
@ -392,6 +396,8 @@
635697C91B14FC11007A7283 /* Tests */ = {
isa = PBXGroup;
children = (
5E3F148A227918C4007C6D90 /* EnableCronet.h */,
5E3F1487227918AA007C6D90 /* EnableCronet.m */,
5EAFE8271F8EFB87007F2189 /* version.h */,
635697D71B14FC11007A7283 /* Supporting Files */,
);
@ -813,6 +819,7 @@
buildActionMask = 2147483647;
files = (
5E3F14852278BF5D007C6D90 /* InteropTestsBlockCallbacks.m in Sources */,
5E3F148D22792856007C6D90 /* EnableCronet.m in Sources */,
5E7F486E22778086006656AD /* CoreCronetEnd2EndTests.mm in Sources */,
5E7F488522778A88006656AD /* InteropTests.m in Sources */,
5E7F486422775B37006656AD /* InteropTestsRemoteWithCronet.m in Sources */,
@ -825,6 +832,7 @@
buildActionMask = 2147483647;
files = (
5E3F14842278B461007C6D90 /* InteropTestsBlockCallbacks.m in Sources */,
5E3F148E22792AF5007C6D90 /* EnableCronet.m in Sources */,
5E7F488922778B04006656AD /* InteropTestsRemote.m in Sources */,
5E7F487922778226006656AD /* InteropTestsMultipleChannels.m in Sources */,
5EA477042273617B000F72FC /* InteropTestsLocalCleartext.m in Sources */,

@ -37,6 +37,11 @@
BlueprintName = "CronetTests"
ReferencedContainer = "container:Tests.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "InteropTests">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
<AdditionalOptions>

Loading…
Cancel
Save