Skip to content

Commit

Permalink
Replace testStoreWithExpirationExtending and testStoreWithExpirationN…
Browse files Browse the repository at this point in the history
…otExtending tests
  • Loading branch information
dstranz committed Jun 3, 2019
1 parent d34061e commit f634115
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions Tests/KingfisherTests/MemoryStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,49 +143,50 @@ class MemoryStorageTests: XCTestCase {
let exp = expectation(description: #function)

XCTAssertFalse(storage.isCached(forKey: "1"))
try! storage.store(value: 1, forKey: "1", expiration: .seconds(0.15))
try! storage.store(value: 1, forKey: "1", expiration: .seconds(1))
XCTAssertTrue(storage.isCached(forKey: "1"))

XCTAssertFalse(storage.isCached(forKey: "2"))
try! storage.store(value: 2, forKey: "2")
XCTAssertTrue(storage.isCached(forKey: "2"))

delay(0.1) {
let expirationDate1 = self.storage.storage.object(forKey: "1")?.estimatedExpiration
XCTAssertNotNil(expirationDate1)

// Request for the object to extend it's expiration date
let obj = self.storage.value(forKey: "1", extendingExpiration: true)
XCTAssertNotNil(obj)
}

delay(0.2) {
XCTAssertTrue(self.storage.isCached(forKey: "1"))
XCTAssertTrue(self.storage.isCached(forKey: "2"))

let expirationDate2 = self.storage.storage.object(forKey: "1")?.estimatedExpiration
XCTAssertNotNil(expirationDate2)

XCTAssertNotEqual(expirationDate1!, expirationDate2!)
XCTAssert(expirationDate1!.isPast(referenceDate: expirationDate2!))
exp.fulfill()
}

waitForExpectations(timeout: 3, handler: nil)
}

func testStoreWithExpirationNotExtending() {
let exp = expectation(description: #function)

XCTAssertFalse(storage.isCached(forKey: "1"))
try! storage.store(value: 1, forKey: "1", expiration: .seconds(0.15))
try! storage.store(value: 1, forKey: "1", expiration: .seconds(1))
XCTAssertTrue(storage.isCached(forKey: "1"))

XCTAssertFalse(storage.isCached(forKey: "2"))
try! storage.store(value: 2, forKey: "2")
XCTAssertTrue(storage.isCached(forKey: "2"))

delay(0.1) {
// Request for the object to not extend it's expiration date
let expirationDate1 = self.storage.storage.object(forKey: "1")?.estimatedExpiration
XCTAssertNotNil(expirationDate1)

// Request for the object to extend it's expiration date
let obj = self.storage.value(forKey: "1", extendingExpiration: false)
XCTAssertNotNil(obj)
}

delay(0.2) {
XCTAssertFalse(self.storage.isCached(forKey: "1"))
XCTAssertTrue(self.storage.isCached(forKey: "2"))
let expirationDate2 = self.storage.storage.object(forKey: "1")?.estimatedExpiration
XCTAssertNotNil(expirationDate2)

XCTAssertEqual(expirationDate1, expirationDate2)
exp.fulfill()
}

waitForExpectations(timeout: 3, handler: nil)
}

Expand Down

0 comments on commit f634115

Please sign in to comment.