Skip to content

Commit e232a67

Browse files
authored
fix: add support for multiple clients (#410)
This is an umbrella PR of several fixes to support multiple clients (sdkKeys). - full thread-safety for additional concurrency requirements - no resource conflicts for multiple sdkKeys support
1 parent c54dfb9 commit e232a67

18 files changed

+391
-147
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ build
4343
# We recommend against adding the Pods directory to your .gitignore. However
4444
# you should judge for yourself, the pros and cons are mentioned at:
4545
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
46-
4746
Pods/
4847

48+
# COCOAPODS version at the end of Podfile.lock requires all stick to the same version
49+
# Ignore this and stick pods to fixed versions in Podfile
50+
Podfile.lock
51+
4952
# Carthage
5053
#
5154
# Add this line if you want to avoid checking in source code from Carthage dependencies.

DemoObjCApp/DemoObjcApp.xcodeproj/xcshareddata/xcschemes/DemoObjctvOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1240"
3+
LastUpgradeVersion = "1230"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

OptimizelySwiftSDK.xcodeproj/project.pbxproj

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,39 @@
15191519
6ECB60D7234E601A00016D41 /* OptimizelyClientTests_OptimizelyConfig_Objc.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ECB60D6234E601A00016D41 /* OptimizelyClientTests_OptimizelyConfig_Objc.m */; };
15201520
6EE5911A2649CF640013AD66 /* LoggerTests_MultiClients.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EE591192649CF640013AD66 /* LoggerTests_MultiClients.swift */; };
15211521
6EE5918E264AF44B0013AD66 /* HandlerRegistryServiceTests_MultiClients.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EE5918D264AF44B0013AD66 /* HandlerRegistryServiceTests_MultiClients.swift */; };
1522+
6EE59285264DCD100013AD66 /* MultiClientsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EE59284264DCD100013AD66 /* MultiClientsTests.swift */; };
1523+
6EE59296264DF4990013AD66 /* feature_exp.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75197622C5211100B2B157 /* feature_exp.json */; };
1524+
6EE59297264DF4990013AD66 /* bot_filtering_enabled.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75197B22C5211100B2B157 /* bot_filtering_enabled.json */; };
1525+
6EE59298264DF4990013AD66 /* bucketer_test.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75197822C5211100B2B157 /* bucketer_test.json */; };
1526+
6EE59299264DF4990013AD66 /* bucketer_test2.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75197922C5211100B2B157 /* bucketer_test2.json */; };
1527+
6EE5929A264DF4990013AD66 /* feature_experiments.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75196922C5211100B2B157 /* feature_experiments.json */; };
1528+
6EE5929B264DF4990013AD66 /* audience_targeting.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75197422C5211100B2B157 /* audience_targeting.json */; };
1529+
6EE5929C264DF4990013AD66 /* unsupported_version.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75197D22C5211100B2B157 /* unsupported_version.json */; };
1530+
6EE5929D264DF4990013AD66 /* feature_variables.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75196F22C5211100B2B157 /* feature_variables.json */; };
1531+
6EE5929E264DF4990013AD66 /* feature_rollout_toggle_on.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75196722C5211100B2B157 /* feature_rollout_toggle_on.json */; };
1532+
6EE5929F264DF4990013AD66 /* rollout_bucketing.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75196C22C5211100B2B157 /* rollout_bucketing.json */; };
1533+
6EE592A0264DF4990013AD66 /* feature_management_experiment_bucketing.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75196D22C5211100B2B157 /* feature_management_experiment_bucketing.json */; };
1534+
6EE592A1264DF4990013AD66 /* typed_audience_datafile.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75197522C5211100B2B157 /* typed_audience_datafile.json */; };
1535+
6EE592A2264DF4990013AD66 /* bucketer_test3.json in Resources */ = {isa = PBXBuildFile; fileRef = 6EA0FB1E251A5AEC00EC002D /* bucketer_test3.json */; };
1536+
6EE592A3264DF4990013AD66 /* empty_datafile.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75197722C5211100B2B157 /* empty_datafile.json */; };
1537+
6EE592A4264DF4990013AD66 /* empty_datafile_new_revision.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E34A624231ED04900BAE302 /* empty_datafile_new_revision.json */; };
1538+
6EE592A5264DF4990013AD66 /* feature_rollout_toggle_off.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75196822C5211100B2B157 /* feature_rollout_toggle_off.json */; };
1539+
6EE592A6264DF4990013AD66 /* empty_datafile_new_account_id.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E34A63D231ED28600BAE302 /* empty_datafile_new_account_id.json */; };
1540+
6EE592A7264DF4990013AD66 /* ab_experiments.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75197A22C5211100B2B157 /* ab_experiments.json */; };
1541+
6EE592A8264DF4990013AD66 /* optimizely_6372300739_v4.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75196222C5211100B2B157 /* optimizely_6372300739_v4.json */; };
1542+
6EE592A9264DF4990013AD66 /* feature_flag.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75197122C5211100B2B157 /* feature_flag.json */; };
1543+
6EE592AA264DF4990013AD66 /* simple_datafile.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75197C22C5211100B2B157 /* simple_datafile.json */; };
1544+
6EE592AB264DF4990013AD66 /* empty_datafile_new_project_id.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E34A623231ED04900BAE302 /* empty_datafile_new_project_id.json */; };
1545+
6EE592AC264DF4990013AD66 /* unsupported_datafile.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75196B22C5211100B2B157 /* unsupported_datafile.json */; };
1546+
6EE592AD264DF4990013AD66 /* api_datafile.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75197022C5211100B2B157 /* api_datafile.json */; };
1547+
6EE592AE264DF4990013AD66 /* bucketing_id.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75196E22C5211100B2B157 /* bucketing_id.json */; };
1548+
6EE592AF264DF4990013AD66 /* grouped_experiments.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75197222C5211100B2B157 /* grouped_experiments.json */; };
1549+
6EE592B0264DF4990013AD66 /* feature_rollouts.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75197322C5211100B2B157 /* feature_rollouts.json */; };
1550+
6EE592B1264DF4990013AD66 /* forced_variation.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75196A22C5211100B2B157 /* forced_variation.json */; };
1551+
6EE592C2264DF4A70013AD66 /* 50_entities.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75196522C5211100B2B157 /* 50_entities.json */; };
1552+
6EE592C3264DF4A70013AD66 /* 10_entities.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75196422C5211100B2B157 /* 10_entities.json */; };
1553+
6EE592C4264DF4A70013AD66 /* 100_entities.json in Resources */ = {isa = PBXBuildFile; fileRef = 6E75196622C5211100B2B157 /* 100_entities.json */; };
1554+
6EE592D5264EDAED0013AD66 /* decide_datafile.json in Resources */ = {isa = PBXBuildFile; fileRef = 6EF8DE0524B8DA58008B9488 /* decide_datafile.json */; };
15221555
6EF41A332522BE1900EAADF1 /* OptimizelyUserContextTests_Decide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2D34B8250AD14000A0CDFE /* OptimizelyUserContextTests_Decide.swift */; };
15231556
6EF41A422522BE2100EAADF1 /* OptimizelyUserContextTests_Decide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2D34B8250AD14000A0CDFE /* OptimizelyUserContextTests_Decide.swift */; };
15241557
6EF8DE0624B8DA58008B9488 /* decide_datafile.json in Resources */ = {isa = PBXBuildFile; fileRef = 6EF8DE0524B8DA58008B9488 /* decide_datafile.json */; };
@@ -2034,6 +2067,7 @@
20342067
6ECB60D6234E601A00016D41 /* OptimizelyClientTests_OptimizelyConfig_Objc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OptimizelyClientTests_OptimizelyConfig_Objc.m; sourceTree = "<group>"; };
20352068
6EE591192649CF640013AD66 /* LoggerTests_MultiClients.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggerTests_MultiClients.swift; sourceTree = "<group>"; };
20362069
6EE5918D264AF44B0013AD66 /* HandlerRegistryServiceTests_MultiClients.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandlerRegistryServiceTests_MultiClients.swift; sourceTree = "<group>"; };
2070+
6EE59284264DCD100013AD66 /* MultiClientsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiClientsTests.swift; sourceTree = "<group>"; };
20372071
6EF8DE0524B8DA58008B9488 /* decide_datafile.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = decide_datafile.json; sourceTree = "<group>"; };
20382072
6EF8DE0A24BD1BB1008B9488 /* OptimizelyDecision.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OptimizelyDecision.swift; sourceTree = "<group>"; };
20392073
6EF8DE0B24BD1BB2008B9488 /* OptimizelyDecideOption.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OptimizelyDecideOption.swift; sourceTree = "<group>"; };
@@ -2240,6 +2274,7 @@
22402274
6E474C8C263C889E00ABDFF8 /* UserProfileServiceTests_MultiClients.swift */,
22412275
6EE591192649CF640013AD66 /* LoggerTests_MultiClients.swift */,
22422276
6EE5918D264AF44B0013AD66 /* HandlerRegistryServiceTests_MultiClients.swift */,
2277+
6EE59284264DCD100013AD66 /* MultiClientsTests.swift */,
22432278
6E6419FD265734C100C49555 /* ProjectConfigTests_MultiClients.swift */,
22442279
6E6419D92657059700C49555 /* NotificationCenterTests_MultiClients.swift */,
22452280
);
@@ -3132,6 +3167,38 @@
31323167
isa = PBXResourcesBuildPhase;
31333168
buildActionMask = 2147483647;
31343169
files = (
3170+
6EE5929E264DF4990013AD66 /* feature_rollout_toggle_on.json in Resources */,
3171+
6EE592A7264DF4990013AD66 /* ab_experiments.json in Resources */,
3172+
6EE592A4264DF4990013AD66 /* empty_datafile_new_revision.json in Resources */,
3173+
6EE592AA264DF4990013AD66 /* simple_datafile.json in Resources */,
3174+
6EE592AD264DF4990013AD66 /* api_datafile.json in Resources */,
3175+
6EE592C3264DF4A70013AD66 /* 10_entities.json in Resources */,
3176+
6EE592C2264DF4A70013AD66 /* 50_entities.json in Resources */,
3177+
6EE592AF264DF4990013AD66 /* grouped_experiments.json in Resources */,
3178+
6EE592A6264DF4990013AD66 /* empty_datafile_new_account_id.json in Resources */,
3179+
6EE592B0264DF4990013AD66 /* feature_rollouts.json in Resources */,
3180+
6EE5929C264DF4990013AD66 /* unsupported_version.json in Resources */,
3181+
6EE5929A264DF4990013AD66 /* feature_experiments.json in Resources */,
3182+
6EE592A9264DF4990013AD66 /* feature_flag.json in Resources */,
3183+
6EE592C4264DF4A70013AD66 /* 100_entities.json in Resources */,
3184+
6EE5929D264DF4990013AD66 /* feature_variables.json in Resources */,
3185+
6EE592B1264DF4990013AD66 /* forced_variation.json in Resources */,
3186+
6EE592A1264DF4990013AD66 /* typed_audience_datafile.json in Resources */,
3187+
6EE59297264DF4990013AD66 /* bot_filtering_enabled.json in Resources */,
3188+
6EE592AB264DF4990013AD66 /* empty_datafile_new_project_id.json in Resources */,
3189+
6EE592D5264EDAED0013AD66 /* decide_datafile.json in Resources */,
3190+
6EE592A2264DF4990013AD66 /* bucketer_test3.json in Resources */,
3191+
6EE59299264DF4990013AD66 /* bucketer_test2.json in Resources */,
3192+
6EE592AC264DF4990013AD66 /* unsupported_datafile.json in Resources */,
3193+
6EE592A8264DF4990013AD66 /* optimizely_6372300739_v4.json in Resources */,
3194+
6EE5929F264DF4990013AD66 /* rollout_bucketing.json in Resources */,
3195+
6EE592A0264DF4990013AD66 /* feature_management_experiment_bucketing.json in Resources */,
3196+
6EE59298264DF4990013AD66 /* bucketer_test.json in Resources */,
3197+
6EE592AE264DF4990013AD66 /* bucketing_id.json in Resources */,
3198+
6EE59296264DF4990013AD66 /* feature_exp.json in Resources */,
3199+
6EE5929B264DF4990013AD66 /* audience_targeting.json in Resources */,
3200+
6EE592A5264DF4990013AD66 /* feature_rollout_toggle_off.json in Resources */,
3201+
6EE592A3264DF4990013AD66 /* empty_datafile.json in Resources */,
31353202
);
31363203
runOnlyForDeploymentPostprocessing = 0;
31373204
};
@@ -3756,6 +3823,7 @@
37563823
6EE5918E264AF44B0013AD66 /* HandlerRegistryServiceTests_MultiClients.swift in Sources */,
37573824
6E424CD526324B270081004A /* OptimizelyClient.swift in Sources */,
37583825
6E424CD626324B270081004A /* OptimizelyClient+ObjC.swift in Sources */,
3826+
6EE59285264DCD100013AD66 /* MultiClientsTests.swift in Sources */,
37593827
6E424CD726324B270081004A /* OptimizelyResult.swift in Sources */,
37603828
6E424CD826324B270081004A /* OptimizelyConfig.swift in Sources */,
37613829
6E424CD926324B270081004A /* OptimizelyConfig+ObjC.swift in Sources */,

Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ end
1010
def linter_pods
1111
# ignore all warnings from all dependencies
1212
inhibit_all_warnings!
13-
pod 'SwiftLint'
13+
pod 'SwiftLint', '0.43.1'
1414
end
1515

1616
def common_test_pods

Podfile.lock

Lines changed: 0 additions & 20 deletions
This file was deleted.

Sources/Extensions/OptimizelyClient+Extension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ extension OptimizelyClient {
7575

7676
let interval = periodicDownloadInterval ?? 10 * 60
7777
if interval > 0 {
78-
self.currentDatafileHandler?.setPeriodicInterval(sdkKey: sdkKey, interval: interval)
78+
self.datafileHandler?.setPeriodicInterval(sdkKey: sdkKey, interval: interval)
7979
}
8080
}
8181

Sources/Optimizely/OptimizelyClient.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,23 @@ open class OptimizelyClient: NSObject {
4747

4848
lazy var logger = OPTLoggerFactory.getLogger()
4949

50-
var eventDispatcher: OPTEventDispatcher? {
50+
lazy var eventDispatcher: OPTEventDispatcher? = {
5151
return HandlerRegistryService.shared.injectEventDispatcher(sdkKey: self.sdkKey)
52-
}
52+
}()
5353

54-
public var datafileHandler: OPTDatafileHandler? {
54+
public lazy var datafileHandler: OPTDatafileHandler? = {
5555
return HandlerRegistryService.shared.injectDatafileHandler(sdkKey: self.sdkKey)
56-
}
57-
lazy var currentDatafileHandler = datafileHandler
56+
}()
5857

5958
// MARK: - Default Services
6059

61-
var decisionService: OPTDecisionService {
62-
return HandlerRegistryService.shared.injectDecisionService(sdkKey: self.sdkKey)!
63-
}
60+
lazy var decisionService: OPTDecisionService! = {
61+
return HandlerRegistryService.shared.injectDecisionService(sdkKey: self.sdkKey)
62+
}()
6463

65-
public var notificationCenter: OPTNotificationCenter? {
64+
public lazy var notificationCenter: OPTNotificationCenter? = {
6665
return HandlerRegistryService.shared.injectNotificationCenter(sdkKey: self.sdkKey)
67-
}
66+
}()
6867

6968
// MARK: - Public interfaces
7069

Tests/OptimizelyTests-APIs/OptimizelyClientTests_DatafileHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class OptimizelyClientTests_DatafileHandler: XCTestCase {
3232

3333
func testOptimizelyClientWithCachedDatafile() {
3434
// create test datafile handler
35-
let handler = MockDatafileHandler(statusCode: 0, passError: false, localResponseData: OTUtils.loadJSONDatafileString("api_datafile"))
35+
let handler = MockDatafileHandler(statusCode: 200, localResponseData: OTUtils.loadJSONDatafileString("api_datafile"))
3636
//save the cached datafile..
3737
let data = OTUtils.loadJSONDatafile("api_datafile")
3838

0 commit comments

Comments
 (0)