Skip to content

[FME-4184] Splits Parsing Fix #671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 3, 2025
Merged
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
11 changes: 4 additions & 7 deletions .github/workflows/test_all.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
name: Build and Test iOS

on:
workflow_run:
workflows: ["Sonar Scan"]
types:
- completed
pull_request:
branches:
- master
- development
- "*_baseline"
- master
- development
- "*_baseline"

# Cancel in-progress runs when a new workflow with the same group is triggered
concurrency:
Expand Down
2 changes: 1 addition & 1 deletion Split/Models/SplitModel/Split.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class SplitDTO: NSObject, SplitBase, Codable {
var impressionsDisabled: Bool?
var prerequisites: [Prerequisite]?

// SDK loading optimization
var json: String = ""

var isCompletelyParsed = true

init(name: String, trafficType: String, status: Status, sets: Set<String>?, json: String, killed: Bool = false, impressionsDisabled: Bool = false) {
Expand Down
7 changes: 5 additions & 2 deletions Split/Storage/Splits/SplitsStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class DefaultSplitsStorage: SplitsStorage {
}

func get(name: String) -> Split? {
guard let split = inMemorySplits.value(forKey: name.lowercased()) else {
let lowercasedName = name.lowercased()

guard let split = inMemorySplits.value(forKey: lowercasedName) else {
return nil
}
if !split.isCompletelyParsed {
Expand All @@ -66,7 +68,8 @@ class DefaultSplitsStorage: SplitsStorage {
parsed.conditions = [SplitHelper.createDefaultCondition()]
}

inMemorySplits.setValue(parsed, forKey: name)
parsed.isCompletelyParsed = true
inMemorySplits.setValue(parsed, forKey: lowercasedName)
return parsed
}
return nil
Expand Down
123 changes: 121 additions & 2 deletions SplitTests/Helpers/SplitTestHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,127 @@ class SplitTestHelper {
}

static func newSplit(name: String, trafficType: String) -> Split {
let split = Split(name: name, trafficType: trafficType, status: .active, sets: nil, json: "")
split.isCompletelyParsed = true

let splitJSONExample = """
{
"trafficTypeName":"\(trafficType)",
"name": "\(name)\",
"trafficAllocation":59,
"trafficAllocationSeed":-2108186082,
"seed":-1947050785,
"status":"ACTIVE",
"killed":false,
"defaultTreatment":"off",
"changeNumber":1506703262916,
"algo":2,
"conditions":[
{
"conditionType":"WHITELIST",
"matcherGroup":{
"combiner":"AND",
"matchers":[
{
"keySelector":null,
"matcherType":"WHITELIST",
"negate":false,
"userDefinedSegmentMatcherData":null,
"whitelistMatcherData":{
"whitelist":[
"nico_test",
"othertest"
]
},
"unaryNumericMatcherData":null,
"betweenMatcherData":null,
"booleanMatcherData":null,
"dependencyMatcherData":null,
"stringMatcherData":null
}
]
},
"partitions":[
{
"treatment":"on",
"size":100
}
],
"label":"whitelisted"
},
{
"conditionType":"WHITELIST",
"matcherGroup":{
"combiner":"AND",
"matchers":[
{
"keySelector":null,
"matcherType":"WHITELIST",
"negate":false,
"userDefinedSegmentMatcherData":null,
"whitelistMatcherData":{
"whitelist":[
"bla"
]
},
"unaryNumericMatcherData":null,
"betweenMatcherData":null,
"booleanMatcherData":null,
"dependencyMatcherData":null,
"stringMatcherData":null
}
]
},
"partitions":[
{
"treatment":"off",
"size":100
}
],
"label":"whitelisted"
},
{
"conditionType":"ROLLOUT",
"matcherGroup":{
"combiner":"AND",
"matchers":[
{
"keySelector":{
"trafficType":"account",
"attribute":null
},
"matcherType":"ALL_KEYS",
"negate":false,
"userDefinedSegmentMatcherData":null,
"whitelistMatcherData":null,
"unaryNumericMatcherData":null,
"betweenMatcherData":null,
"booleanMatcherData":null,
"dependencyMatcherData":null,
"stringMatcherData":null
}
]
},
"partitions":[
{
"treatment":"on",
"size":0
},
{
"treatment":"off",
"size":100
},
{
"treatment":"visa",
"size":0
}
],
"label":"in segment all"
}
]
}
"""

let split = Split(name: name, trafficType: trafficType, status: .active, sets: nil, json: splitJSONExample)
split.isCompletelyParsed = false
return split
}
}
4 changes: 2 additions & 2 deletions SplitTests/SplitManagerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class SplitManagerTest: XCTestCase {
changeNumber: 2, updateTimestamp: 200))
let splits = manager.splits
let names = manager.splitNames
XCTAssertEqual(splits.count, 7, "Added one feature flag count")
XCTAssertEqual(names.sorted().joined(separator: ",").lowercased(), "sample_feature0,sample_feature1,sample_feature2,sample_feature3,sample_feature4,sample_feature5,sample_feature6", "Added one feature flag name check")
XCTAssertEqual(splits.count, 9, "Added one feature flag count")
XCTAssertEqual(names.sorted().joined(separator: ",").lowercased(), "sample_feature0,sample_feature1,sample_feature2,sample_feature3,sample_feature4,sample_feature5,sample_feature6,always_on_if_prerequisite,rbs_test_flag","Added one feature flag name check")
}

func testEmptyName(){
Expand Down
35 changes: 35 additions & 0 deletions SplitTests/Storage/SplitsStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,41 @@ class SplitsStorageTest: XCTestCase {
XCTAssertEqual(1, splits.keys.filter { return $0 == "added1"}.count)
XCTAssertTrue(persistentStorage.updateCalled)
}

func testFetchTwiceParseOnce() {

persistentStorage.snapshot = getTestSnapshot()
splitsStorage.loadLocal()

let split = newSplit(name: "TwiceTestSplit")
XCTAssertFalse(split.isCompletelyParsed, "A new Split shouln't be parsed yet")

let processedChange = ProcessedSplitChange(activeSplits: [split],
archivedSplits: [],
changeNumber: 999, updateTimestamp: 888)

_ = splitsStorage.update(splitChange: processedChange)
let splitGet = splitsStorage.get(name: "TwiceTestSplit")

XCTAssert(splitGet!.isCompletelyParsed, "After getting it once, the Split it should be parsed")
}

func testFetchCaseInsensitive() {

persistentStorage.snapshot = getTestSnapshot()
splitsStorage.loadLocal()

let split = newSplit(name: "TwiceTestSplit")
XCTAssertFalse(split.isCompletelyParsed)

let processedChange = ProcessedSplitChange(activeSplits: [split],
archivedSplits: [],
changeNumber: 999, updateTimestamp: 888)

_ = splitsStorage.update(splitChange: processedChange)
_ = splitsStorage.get(name: "TwiceTestSplit")
XCTAssertNotNil(splitsStorage.getAll()["twicetestsplit"])
}

func testUpdateEmptySplits() {

Expand Down
Loading