diff --git a/Sources/Confidence/FlagEvaluation.swift b/Sources/Confidence/FlagEvaluation.swift index 393fbc2a..c04d6c61 100644 --- a/Sources/Confidence/FlagEvaluation.swift +++ b/Sources/Confidence/FlagEvaluation.swift @@ -44,11 +44,7 @@ extension FlagResolution { ) } - if resolvedFlag.resolveReason != .targetingKeyError { - Task { - await flagApplier?.apply(flagName: parsedKey.flag, resolveToken: self.resolveToken) - } - } else { + if resolvedFlag.resolveReason == .targetingKeyError { return Evaluation( value: defaultValue, variant: nil, @@ -59,6 +55,9 @@ extension FlagResolution { } guard let value = resolvedFlag.value else { + Task { + await flagApplier?.apply(flagName: parsedKey.flag, resolveToken: self.resolveToken) + } return Evaluation( value: defaultValue, variant: resolvedFlag.variant, @@ -77,6 +76,9 @@ extension FlagResolution { resolveReason = .stale } if let typedValue = typedValue { + Task { + await flagApplier?.apply(flagName: parsedKey.flag, resolveToken: self.resolveToken) + } return Evaluation( value: typedValue, variant: resolvedFlag.variant, @@ -87,6 +89,9 @@ extension FlagResolution { } else { // `null` type from backend instructs to use client-side default value if parsedValue == .init(null: ()) { + Task { + await flagApplier?.apply(flagName: parsedKey.flag, resolveToken: self.resolveToken) + } return Evaluation( value: defaultValue, variant: resolvedFlag.variant, @@ -105,6 +110,9 @@ extension FlagResolution { } } } else { + Task { + await flagApplier?.apply(flagName: parsedKey.flag, resolveToken: self.resolveToken) + } return Evaluation( value: defaultValue, variant: resolvedFlag.variant, diff --git a/Tests/ConfidenceTests/ConfidenceTest.swift b/Tests/ConfidenceTests/ConfidenceTest.swift index e99988c4..51dc65d5 100644 --- a/Tests/ConfidenceTests/ConfidenceTest.swift +++ b/Tests/ConfidenceTests/ConfidenceTest.swift @@ -694,6 +694,7 @@ class ConfidenceTest: XCTestCase { XCTAssertNil(evaluation.errorMessage, "") XCTAssertEqual(evaluation.reason, .error) XCTAssertEqual(evaluation.variant, nil) + XCTAssertEqual(flagApplier.applyCallCount, 0) } func testConcurrentActivate() async {