Skip to content

Commit

Permalink
Update AutoPollingTests.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein committed Nov 29, 2022
1 parent b649e82 commit ea73226
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Tests/ConfigCatTests/AutoPollingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,32 @@ class AutoPollingTests: XCTestCase {
XCTAssert(elapsedTimeInSeconds < 1)
}

func testCacheIsNotExpiredCallsOnReady() throws {
let engine = MockEngine()
engine.enqueueResponse(response: Response(body: String(format: testJsonFormat, "test"), statusCode: 200, delay: 5))

var ready = false
let hooks = Hooks()
hooks.addOnReady {
ready = true
}
let initValue = String(format: testJsonFormat, "test").asEntryString()
let cache = SingleValueCache(initValue: initValue)
let mode = PollingModes.autoPoll(autoPollIntervalInSeconds: 60, maxInitWaitTimeInSeconds: 1)
let fetcher = ConfigFetcher(httpEngine: engine, logger: Logger.noLogger, sdkKey: "", mode: mode.identifier, dataGovernance: .global)
let service = ConfigService(log: Logger.noLogger, fetcher: fetcher, cache: cache, pollingMode: mode, hooks: hooks, sdkKey: "", offline: false)

let expectation1 = expectation(description: "wait for settings")
service.settings { settingsResult in
XCTAssertFalse(settingsResult.settings.isEmpty)
expectation1.fulfill()
}
wait(for: [expectation1], timeout: 5)

XCTAssertTrue(engine.requests.isEmpty)
XCTAssertTrue(ready)
}

func testInitWaitTimeReturnCached() throws {
let engine = MockEngine()
engine.enqueueResponse(response: Response(body: String(format: testJsonFormat, "test"), statusCode: 200, delay: 5))
Expand Down

0 comments on commit ea73226

Please sign in to comment.