Skip to content

Commit

Permalink
A small test warning on Sendable
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Dec 14, 2024
1 parent 623e159 commit c658b5c
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions Tests/KingfisherTests/ImageCacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class ImageCacheTests: XCTestCase {
override func tearDown() {
clearCaches([cache])
cache = nil
observer = nil
if let o = observer {
NotificationCenter.default.removeObserver(o)
observer = nil
}

super.tearDown()
}
Expand Down Expand Up @@ -351,28 +354,27 @@ class ImageCacheTests: XCTestCase {

cache.diskStorage.config.expiration = .seconds(0.01)

let selfCache = self.cache
cache.store(testImage, original: testImageData, forKey: key, toDisk: true) { _ in
self.observer = NotificationCenter.default.addObserver(
forName: .KingfisherDidCleanDiskCache,
object: self.cache,
queue: .main) {
noti in
let receivedCache = noti.object as? ImageCache
XCTAssertNotNil(receivedCache)
XCTAssertTrue(receivedCache === self.cache)

guard let hashes = noti.userInfo?[KingfisherDiskCacheCleanedHashKey] as? [String] else {
XCTFail("Notification should contains Strings in key 'KingfisherDiskCacheCleanedHashKey'")
exp.fulfill()
return
}

XCTAssertEqual(hashes.count, 1)
XCTAssertEqual(hashes.first!, self.cache.hash(forKey: key))
guard let o = self.observer else { return }
NotificationCenter.default.removeObserver(o)
queue: .main
) { noti in
let receivedCache = noti.object as? ImageCache
XCTAssertNotNil(receivedCache)
XCTAssertTrue(receivedCache === selfCache)

guard let hashes = noti.userInfo?[KingfisherDiskCacheCleanedHashKey] as? [String] else {
XCTFail("Notification should contains Strings in key 'KingfisherDiskCacheCleanedHashKey'")
exp.fulfill()
return
}

XCTAssertEqual(hashes.count, 1)
XCTAssertEqual(hashes.first!, selfCache!.hash(forKey: key))
exp.fulfill()
}

delay(1) {
self.cache.cleanExpiredDiskCache()
Expand Down

0 comments on commit c658b5c

Please sign in to comment.