-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(handler-registry-service): add support for multiple clients #406
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
e07ee4a
add multi-client tests for datafile handler
jaeopt b4153a0
fix datafile handler sync with atomic dictionary
jaeopt bfabdae
change name for AtomicWrapper
jaeopt e7091de
remove extra line from custom xcode header
jaeopt 6282d4d
add more concurrent tests for datafile handler
jaeopt e21b11d
clean up
jaeopt 65d11fa
change tests to a shared datafile handler
jaeopt 826d40b
fix atomic return
jaeopt 77fb808
clean up
jaeopt d6d9fac
clean up
jaeopt e852348
fix per review
jaeopt e375243
clean up
jaeopt 5425df3
clean up
jaeopt 5888f66
clean up
jaeopt f741634
add tests for concurrent event dispatcher
jaeopt 181d86f
clean up tests
jaeopt d1dc2fe
add more tests for multi-client event dispatcher
jaeopt 3a6aad9
clean up
jaeopt 0ae0fbd
fix conflicts
jaeopt 34b0f9f
add tests for multi-client ups
jaeopt 5a73bc3
add rmwlock for ups
jaeopt 7be7064
add global ups lock
jaeopt 0c00ecc
move a shred ups lock to decision-service
jaeopt 32e3a55
fix per review
jaeopt 61bd1b5
add logger tests for multi clients
jaeopt 05ce575
fix handlerRegistryService to support multi clients
jaeopt 4a87114
clean up
jaeopt 620013c
fix conflicts
jaeopt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
Tests/OptimizelyTests-MultiClients/HandlerRegistryServiceTests_MultiClients.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// | ||
// Copyright 2021, Optimizely, Inc. and contributors | ||
// | ||
// 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 XCTest | ||
|
||
class HandlerRegistryServiceTests_MultiClients: XCTestCase { | ||
|
||
override func setUpWithError() throws { | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
} | ||
|
||
func testConcurrentAccess_Singleton() { | ||
// this type used for all handlers except for logger | ||
|
||
let numThreads = 10 | ||
let numEventsPerThread = 100 | ||
|
||
let registry = HandlerRegistryService.shared | ||
|
||
let result = OTUtils.runConcurrent(count: numThreads, timeoutInSecs: 300) { thIdx in | ||
for idx in 0..<numEventsPerThread { | ||
let sdkKey = String(thIdx * numEventsPerThread + idx) | ||
let strategy: ReInitializeStrategy = .reUse | ||
let isSingleton = true | ||
let isReinitialize = false | ||
|
||
let service = OPTLogger.self | ||
let componentIn = DefaultLogger() | ||
|
||
let binder = Binder(sdkKey: sdkKey, | ||
service: service, | ||
strategy: strategy, | ||
isSingleton: isSingleton, | ||
inst: componentIn) | ||
|
||
registry.registerBinding(binder: binder) | ||
if let componentOut = registry.injectComponent(service: service, | ||
sdkKey: sdkKey, | ||
isReintialize: isReinitialize) as? DefaultLogger { | ||
XCTAssertEqual(String(describing: componentOut), String(describing: componentIn)) | ||
} else { | ||
self.dumpRegistry() | ||
XCTAssert(false, "injectComponent failed: \(sdkKey) :: \(binder)") | ||
} | ||
} | ||
} | ||
|
||
XCTAssertTrue(result, "Concurrent tasks timed out") | ||
} | ||
|
||
func testConcurrentAccess_NonSingleton() { | ||
// this type used for loggers | ||
|
||
let numThreads = 10 | ||
let numEventsPerThread = 100 | ||
|
||
let registry = HandlerRegistryService.shared | ||
|
||
let result = OTUtils.runConcurrent(count: numThreads, timeoutInSecs: 300) { thIdx in | ||
for _ in 0..<numEventsPerThread { | ||
let isReinitialize = false | ||
|
||
let service = OPTLogger.self | ||
let componentIn = DefaultLogger() | ||
|
||
let binder = Binder<OPTLogger>(service: service, | ||
factory: type(of: componentIn).init) | ||
|
||
registry.registerBinding(binder: binder) | ||
if let componentOut = registry.injectComponent(service: service, | ||
isReintialize: isReinitialize) as? DefaultLogger { | ||
XCTAssertEqual(String(describing: componentOut), String(describing: componentIn)) | ||
} else { | ||
self.dumpRegistry() | ||
XCTAssert(false, "injectComponent failed: \(binder)") | ||
} | ||
} | ||
} | ||
|
||
XCTAssertTrue(result, "Concurrent tasks timed out") | ||
} | ||
|
||
func testConcurrentAccess_Random() { | ||
let numThreads = 10 | ||
let numEventsPerThread = 100 | ||
|
||
let registry = HandlerRegistryService.shared | ||
|
||
let result = OTUtils.runConcurrent(count: numThreads, timeoutInSecs: 300) { thIdx in | ||
for idx in 0..<numEventsPerThread { | ||
let sdkKey = String(thIdx * numEventsPerThread + idx) | ||
let strategy: ReInitializeStrategy = Bool.random() ? .reCreate : .reUse | ||
let isSingleton = Bool.random() | ||
let isReinitialize = Bool.random() | ||
|
||
let service = OPTLogger.self | ||
let componentIn = DefaultLogger() | ||
|
||
let binder = Binder(sdkKey: sdkKey, | ||
service: service, | ||
strategy: strategy, | ||
factory: type(of: componentIn).init, | ||
isSingleton: isSingleton, | ||
inst: componentIn) | ||
|
||
registry.registerBinding(binder: binder) | ||
if let componentOut = registry.injectComponent(service: service, | ||
sdkKey: sdkKey, | ||
isReintialize: isReinitialize) as? DefaultLogger { | ||
XCTAssertEqual(String(describing: componentOut), String(describing: componentIn)) | ||
} else { | ||
self.dumpRegistry() | ||
XCTAssert(false, "injectComponent failed: \(sdkKey) \(isReinitialize) :: \(binder)") | ||
} | ||
} | ||
} | ||
|
||
XCTAssertTrue(result, "Concurrent tasks timed out") | ||
} | ||
|
||
// MARK: - Utils | ||
|
||
func dumpRegistry() { | ||
let registry = HandlerRegistryService.shared | ||
|
||
print("[MultiClients] binders --------------") | ||
registry.binders.performAtomic { prop in | ||
for sk in prop.keys { | ||
print("[MultiClients] binder for \(sk): \(prop[sk]!)") | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Tests/OptimizelyTests-MultiClients/LoggerTests_MultiClients.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// Copyright 2021, Optimizely, Inc. and contributors | ||
// | ||
// 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 XCTest | ||
|
||
class LoggerTests_MultiClients: XCTestCase { | ||
|
||
override func setUpWithError() throws { | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add
base
class and put these twooverrided
methods in there and extend classes from thatbase
class. I see these two methods at many locations.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most test cases will use own tasks in these methods. I'll clean up these empty methods.