Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions DevCycle/Models/DVCConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,34 @@ import Foundation
public class DVCConfig {
var sdkKey: String
var user: DevCycleUser
private let userConfigQueue = DispatchQueue(
label: "com.devcycle.userConfig", attributes: .concurrent)
private var _userConfig: UserConfig?

var userConfig: UserConfig? {
didSet {
if let userConfig = self.userConfig {
NotificationCenter.default.post(
name: Notification.Name(NotificationNames.NewUserConfig),
object: self,
userInfo: ["new-user-config" : userConfig]
)
get {
return userConfigQueue.sync { _userConfig }
}
set {
// Synchronously set using a barrier to preserve existing semantics
userConfigQueue.async(flags: .barrier) {
self._userConfig = newValue
if let userConfig = newValue {
DispatchQueue.main.async {
NotificationCenter.default.post(
name: Notification.Name(NotificationNames.NewUserConfig),
object: self,
userInfo: ["new-user-config": userConfig]
)
}
}
}
// Fence: wait for the async barrier write above to complete so subsequent reads
// observe the new value immediately (mirrors original didSet synchronous behavior).
userConfigQueue.sync {}
}
}

init(sdkKey: String, user: DevCycleUser) {
self.sdkKey = sdkKey
self.user = user
Expand Down
14 changes: 11 additions & 3 deletions DevCycleTests/Utils/GetTestConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
//

import Foundation
import XCTest

func getConfigData(name: String, withExtension: String = "json") -> Data {
let bundle = Bundle(for: DevCycleClientTest.self)
let fileUrl = bundle.url(forResource: name, withExtension: withExtension)
let data = try! Data(contentsOf: fileUrl!)
#if SWIFT_PACKAGE
let bundle = Bundle.module
#else
let bundle = Bundle(for: DevCycleClientTest.self)
#endif
guard let fileUrl = bundle.url(forResource: name, withExtension: withExtension) else {
XCTFail("Missing test resource: \(name).\(withExtension)")
return Data()
}
let data = try! Data(contentsOf: fileUrl)
return data
}
6 changes: 5 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ let package = Package(
name: "DevCycleTests",
dependencies: ["DevCycle"],
path: "DevCycleTests",
exclude: ["ObjC"]
exclude: ["ObjC"],
resources: [
.process("Models/test_config.json"),
.process("Models/test_config_eval_reason.json"),
]
),
.testTarget(
name: "DevCycleTests-ObjC",
Expand Down
Loading