Skip to content

Commit 116d572

Browse files
(chore): add resourceTimeout tests (#205)
* add resourceTimeout tests * take out performance test * datafile download failing * refactor second test
1 parent d0af856 commit 116d572

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

OptimizelySDK/OptimizelyTests/OptimizelyTests-Common/DatafileHandlerTests.swift

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,45 @@ class DatafileHandlerTests: XCTestCase {
138138

139139
}
140140

141-
142-
func testPerformanceExample() {
143-
// This is an example of a performance test case.
144-
self.measure {
145-
// Put the code you want to measure the time of here.
141+
func testDownloadTimeout() {
142+
let handler = DefaultDatafileHandler()
143+
handler.endPointStringFormat = "https://httpstat.us/200?sleep=5000&datafile=%@"
144+
145+
let expectation = XCTestExpectation(description: "should fail before 10")
146+
handler.downloadDatafile(sdkKey: "invalidKey1212121", resourceTimeoutInterval:3) { (result) in
147+
switch result {
148+
case .failure(let error):
149+
print(error)
150+
XCTAssert(true)
151+
expectation.fulfill()
152+
case .success(let data):
153+
print(data)
154+
XCTAssert(false)
155+
}
146156
}
157+
158+
wait(for: [expectation], timeout: 5.0)
159+
147160
}
161+
162+
func testDownloadWithoutTimeout() {
163+
let handler = DefaultDatafileHandler()
164+
handler.endPointStringFormat = "https://httpstat.us/200?sleep=5000&datafile=%@"
165+
166+
let expectation = XCTestExpectation(description: "will wait for response.")
167+
handler.downloadDatafile(sdkKey: "invalidKeyXXXXX") { (result) in
168+
switch result {
169+
case .failure(let error):
170+
print(error)
171+
XCTAssert(false)
172+
case .success(let data):
173+
print(data ?? "")
174+
XCTAssert(true)
175+
expectation.fulfill()
176+
}
177+
}
148178

179+
wait(for: [expectation], timeout: 10.0)
180+
181+
}
149182
}

0 commit comments

Comments
 (0)