Skip to content

Commit

Permalink
fix: TypeMismatch doesnt trigger apply
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria committed Nov 6, 2024
1 parent 0b00f97 commit 1cd12a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Sources/Confidence/FlagEvaluation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -105,6 +110,9 @@ extension FlagResolution {
}
}
} else {
Task {
await flagApplier?.apply(flagName: parsedKey.flag, resolveToken: self.resolveToken)
}
return Evaluation(
value: defaultValue,
variant: resolvedFlag.variant,
Expand Down
1 change: 1 addition & 0 deletions Tests/ConfidenceTests/ConfidenceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1cd12a7

Please sign in to comment.