Skip to content

Commit

Permalink
Added test to the memory cache test file
Browse files Browse the repository at this point in the history
  • Loading branch information
ashlirankin committed Jan 31, 2023
1 parent 4300fac commit b9f663b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Tests/MemoryCacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,23 @@ final class MemoryCacheTests: XCTestCase {
XCTAssertNotNil(item3)
XCTAssertNotNil(item4)
}

func testUsesCorrectExpirationPolicy() throws {
let expectation = XCTestExpectation(description: "Only one item should have been removed.")

let cache = MemoryCache(capacity: .unlimited, expirationPolicy: .afterInterval(1))
try cache.write(item: TestCodable(), forKey: itemKey, expirationPolicy: .afterInterval(500))

DispatchQueue.main.asyncAfter(deadline: .now() + 2) {

try? cache.removeExpired()

let item1: ItemContainer<TestCodable>? = try? cache.read(forKey: self.itemKey)

XCTAssertNotNil(item1)

expectation.fulfill()
}
wait(for: [expectation], timeout: 5)
}
}

0 comments on commit b9f663b

Please sign in to comment.