Skip to content

Commit 735ed28

Browse files
refactor: lint
Signed-off-by: Fabrizio Demaria <fabrizio.f.demaria@gmail.com>
1 parent b639487 commit 735ed28

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

Sources/OpenFeature/OpenFeatureAPI.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import Foundation
55
/// Configuration here will be shared across all ``Client``s.
66
public class OpenFeatureAPI {
77
private let eventHandler = EventHandler()
8-
private let stateQueue = DispatchQueue(label: "com.openfeature.state.queue") // Sync queue to change state atomically
9-
private let unifiedQueue = AsyncProviderOperationsQueue() // Queue for provider's initialize and onContextSet operations
8+
// Sync queue to change state atomically
9+
private let stateQueue = DispatchQueue(label: "com.openfeature.state.queue")
10+
// Queue for provider's initialize and onContextSet operations
11+
private let unifiedQueue = AsyncProviderOperationsQueue()
1012

1113
private(set) var providerSubject = CurrentValueSubject<FeatureProvider?, Never>(nil)
1214
private(set) var evaluationContext: EvaluationContext?

Tests/OpenFeatureTests/ProviderOperationsQueueTests.swift

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -144,53 +144,39 @@ class ProviderOperationsQueueTests: XCTestCase {
144144
}
145145
}
146146

147-
let endTime = Date()
148-
let duration = endTime.timeIntervalSince(startTime)
149-
150-
// Verify operations completed in reasonable time (no deadlocks)
147+
let duration = Date().timeIntervalSince(startTime)
151148
XCTAssertLessThan(duration, 10.0, "Operations took too long, possible deadlock")
152149

150+
verifyFinalStateConsistency()
151+
}
152+
153+
private func verifyFinalStateConsistency() {
153154
let finalState = OpenFeatureAPI.shared.getState()
154-
// Note: With concurrent TaskGroup execution, the last operation to be enqueued (and thus execute last)
155-
// is non-deterministic. The final state could be from any of the operation types.
156-
// We verify the final state is consistent and valid, regardless of which operation completed last.
155+
// With concurrent execution, the final state is non-deterministic
157156
XCTAssertTrue(
158157
[ProviderStatus.notReady, ProviderStatus.ready].contains(finalState.providerStatus),
159-
"Provider status '\(finalState.providerStatus)' should be in a valid state after high-frequency operations"
158+
"Provider status '\(finalState.providerStatus)' should be valid after high-frequency operations"
160159
)
161160

162-
// Verify state consistency: if provider is nil, status should be notReady
161+
// Verify state consistency
163162
if finalState.provider == nil {
164-
XCTAssertEqual(
165-
finalState.providerStatus,
166-
.notReady,
167-
"When provider is nil, status should be notReady"
168-
)
163+
XCTAssertEqual(finalState.providerStatus, .notReady, "When provider is nil, status should be notReady")
169164
}
170-
171-
// Verify state consistency: if provider exists, status should be ready
172165
if finalState.provider != nil {
173-
XCTAssertEqual(
174-
finalState.providerStatus,
175-
.ready,
176-
"When provider exists, status should be ready"
177-
)
166+
XCTAssertEqual(finalState.providerStatus, .ready, "When provider exists, status should be ready")
178167
}
179168

180-
let context = finalState.evaluationContext
181-
let targetingKey = context?.getTargetingKey() ?? ""
182-
if !targetingKey.isEmpty {
169+
// Verify context if present
170+
if let context = finalState.evaluationContext {
171+
let targetingKey = context.getTargetingKey()
183172
XCTAssertTrue(
184173
targetingKey.hasPrefix("rapid-user"),
185-
"Final targeting key '\(targetingKey)' should be from the rapid operations if context exists"
174+
"Final targeting key '\(targetingKey)' should be from rapid operations"
186175
)
187176

188-
let contextMap = context?.asObjectMap() ?? [:]
177+
let contextMap = context.asObjectMap()
189178
if contextMap.keys.contains("iteration") {
190-
XCTAssertTrue(
191-
contextMap.keys.contains("timestamp"),
192-
"Context with iteration should also have timestamp"
193-
)
179+
XCTAssertTrue(contextMap.keys.contains("timestamp"), "Context should have timestamp")
194180
}
195181
}
196182
}

0 commit comments

Comments
 (0)