-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add StatsigOptions.autoValueUpdateIntervalSec (#225)
- Loading branch information
1 parent
f78f858
commit 25b5c58
Showing
8 changed files
with
118 additions
and
28 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import Foundation | ||
|
||
import XCTest | ||
import Nimble | ||
import OHHTTPStubs | ||
import Quick | ||
@testable import Statsig | ||
|
||
#if !COCOAPODS | ||
import OHHTTPStubsSwift | ||
#endif | ||
|
||
final class AutoUpdateSpec: BaseSpec { | ||
override func spec() { | ||
super.spec() | ||
|
||
let opts = StatsigOptions( | ||
enableAutoValueUpdate: true, | ||
autoValueUpdateIntervalSec: 0.001, | ||
api: "http://AutoUpdateSpec" | ||
) | ||
|
||
it("syncs when started from the background thread") { | ||
Statsig.shutdown() | ||
|
||
var callsMade = 0 | ||
stub(condition: isHost("AutoUpdateSpec")) { req in | ||
if (req.url?.absoluteString.contains("/initialize") ?? false) { | ||
callsMade += 1 | ||
} | ||
return HTTPStubsResponse(jsonObject: [:], statusCode: 200, headers: nil) | ||
} | ||
|
||
DispatchQueue.global().sync { | ||
TestUtils.startStatsigAndWait(key: "client-key", nil, opts) | ||
} | ||
|
||
expect(callsMade).toEventually(equal(10)) | ||
} | ||
|
||
it("pulls in changed values") { | ||
Statsig.shutdown() | ||
|
||
var response = [ | ||
"feature_gates": [:], | ||
"dynamic_configs": [:], | ||
"layer_configs": [:], | ||
"has_updates": true | ||
] | ||
|
||
stub(condition: isHost("AutoUpdateSpec")) { req in | ||
return HTTPStubsResponse(jsonObject: response, statusCode: 200, headers: nil) | ||
} | ||
|
||
TestUtils.startStatsigAndWait(key: "client-key", nil, opts) | ||
|
||
expect(Statsig.checkGate("a_gate")).to(beFalse()) | ||
|
||
response = [ | ||
"feature_gates": [ | ||
"a_gate".sha256(): [ | ||
"value": true, | ||
"rule_id": "rule_id_1", | ||
"secondary_exposures": [] | ||
] | ||
], | ||
"dynamic_configs": [:], | ||
"layer_configs": [:], | ||
"has_updates": true | ||
] | ||
|
||
expect(Statsig.checkGate("a_gate")).toEventually(beTrue()) | ||
} | ||
} | ||
} |
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
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