@@ -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