From b9f663ba8acdd84015fbd1a830060cab554f3abb Mon Sep 17 00:00:00 2001 From: Ashli Rankin Date: Tue, 31 Jan 2023 11:37:04 -0500 Subject: [PATCH] Added test to the memory cache test file --- Tests/MemoryCacheTests.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Tests/MemoryCacheTests.swift b/Tests/MemoryCacheTests.swift index 31c0f26..0d35eab 100644 --- a/Tests/MemoryCacheTests.swift +++ b/Tests/MemoryCacheTests.swift @@ -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? = try? cache.read(forKey: self.itemKey) + + XCTAssertNotNil(item1) + + expectation.fulfill() + } + wait(for: [expectation], timeout: 5) + } }