-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ability to use cache over bootstrap (#56)
* chore: address feedback * feat: add ability to use cache over bootstrap * test: verify cache is used instead of bootstrap
- Loading branch information
1 parent
5d97e56
commit 46377c7
Showing
4 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
Tests/StatsigOnDeviceEvaluationsTestsSwift/SynchronousInitTest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import Quick | ||
import Nimble | ||
import XCTest | ||
import StatsigTestUtils | ||
|
||
@testable import StatsigOnDeviceEvaluations | ||
|
||
func getTestDcsWithTimeField(_ res: String, _ time: Int) -> NSString { | ||
var json = TestResources.getJson(res) | ||
json["time"] = time | ||
return String(data: try! JSONSerialization.data(withJSONObject: json), encoding: .utf8)! as NSString | ||
} | ||
|
||
final class SynchronousInitTest: QuickSpec { | ||
override class func spec() { | ||
describe("SynchronousInit") { | ||
let user = StatsigUser(userID: "a-user") | ||
|
||
func primeCache() { | ||
NetworkStubs.clearAllStubs() | ||
|
||
NetworkStubs.stubEndpoint( | ||
endpoint: "download_config_specs", | ||
resource: "RulesetsDownloadConfigsSpecs" | ||
) | ||
|
||
let client = Statsig() | ||
waitUntil { done in | ||
client.initialize("client-key") { _ in done() } | ||
} | ||
|
||
client.shutdown() | ||
|
||
NetworkStubs.clearAllStubs() | ||
} | ||
|
||
it("uses cache if newer and useNewerCacheValuesOverProvidedValues is true") { | ||
primeCache() | ||
|
||
let opts = StatsigOptions() | ||
opts.useNewerCacheValuesOverProvidedValues = true | ||
|
||
let dcs = getTestDcsWithTimeField("EmptyDcs", 123) | ||
let client = Statsig() | ||
let _ = client.initializeSync("client-key", initialSpecs: dcs, options: opts) | ||
|
||
let gate = client.getFeatureGate("test_public", user) | ||
expect(gate.evaluationDetails.reason).to(equal("Cache")) | ||
} | ||
|
||
it("uses bootstrap if useNewerCacheValuesOverProvidedValues is false") { | ||
primeCache() | ||
|
||
let dcs = getTestDcsWithTimeField("RulesetsDownloadConfigsSpecs", 123) | ||
let client = Statsig() | ||
let _ = client.initializeSync("client-key", initialSpecs: dcs) | ||
|
||
let gate = client.getFeatureGate("test_public", user) | ||
expect(gate.evaluationDetails.reason).to(equal("Bootstrap")) | ||
} | ||
|
||
it("uses bootstrap if newer") { | ||
primeCache() | ||
|
||
let opts = StatsigOptions() | ||
opts.useNewerCacheValuesOverProvidedValues = true | ||
|
||
let dcs = getTestDcsWithTimeField("RulesetsDownloadConfigsSpecs", Int.max) | ||
let client = Statsig() | ||
let _ = client.initializeSync("client-key", initialSpecs: dcs, options: opts) | ||
|
||
let gate = client.getFeatureGate("test_public", user) | ||
expect(gate.evaluationDetails.reason).to(equal("Bootstrap")) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"dynamic_configs": [], | ||
"feature_gates": [], | ||
"layer_configs": [], | ||
"id_lists": {}, | ||
"layers": {}, | ||
"has_updates": true, | ||
"time": 1697131166636, | ||
"company_id": "5NprLGRxV3W28hreG51Z7n", | ||
"diagnostics": { | ||
"initialize": 1000, | ||
"dcs": 1000, | ||
"download_config_specs": 1000, | ||
"idlist": 100, | ||
"get_id_list": 100, | ||
"get_id_list_sources": 100, | ||
"log": 100, | ||
"log_event": 100 | ||
} | ||
} |