Skip to content

Commit 670ebed

Browse files
authored
Merge pull request onevcat#2330 from onevcat/fix/test-warning
A small test warning on Sendable
2 parents 623e159 + c658b5c commit 670ebed

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

Tests/KingfisherTests/ImageCacheTests.swift

+19-17
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ class ImageCacheTests: XCTestCase {
4343
override func tearDown() {
4444
clearCaches([cache])
4545
cache = nil
46-
observer = nil
46+
if let o = observer {
47+
NotificationCenter.default.removeObserver(o)
48+
observer = nil
49+
}
4750

4851
super.tearDown()
4952
}
@@ -351,28 +354,27 @@ class ImageCacheTests: XCTestCase {
351354

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

357+
let selfCache = self.cache
354358
cache.store(testImage, original: testImageData, forKey: key, toDisk: true) { _ in
355359
self.observer = NotificationCenter.default.addObserver(
356360
forName: .KingfisherDidCleanDiskCache,
357361
object: self.cache,
358-
queue: .main) {
359-
noti in
360-
let receivedCache = noti.object as? ImageCache
361-
XCTAssertNotNil(receivedCache)
362-
XCTAssertTrue(receivedCache === self.cache)
363-
364-
guard let hashes = noti.userInfo?[KingfisherDiskCacheCleanedHashKey] as? [String] else {
365-
XCTFail("Notification should contains Strings in key 'KingfisherDiskCacheCleanedHashKey'")
366-
exp.fulfill()
367-
return
368-
}
369-
370-
XCTAssertEqual(hashes.count, 1)
371-
XCTAssertEqual(hashes.first!, self.cache.hash(forKey: key))
372-
guard let o = self.observer else { return }
373-
NotificationCenter.default.removeObserver(o)
362+
queue: .main
363+
) { noti in
364+
let receivedCache = noti.object as? ImageCache
365+
XCTAssertNotNil(receivedCache)
366+
XCTAssertTrue(receivedCache === selfCache)
367+
368+
guard let hashes = noti.userInfo?[KingfisherDiskCacheCleanedHashKey] as? [String] else {
369+
XCTFail("Notification should contains Strings in key 'KingfisherDiskCacheCleanedHashKey'")
374370
exp.fulfill()
371+
return
375372
}
373+
374+
XCTAssertEqual(hashes.count, 1)
375+
XCTAssertEqual(hashes.first!, selfCache!.hash(forKey: key))
376+
exp.fulfill()
377+
}
376378

377379
delay(1) {
378380
self.cache.cleanExpiredDiskCache()

0 commit comments

Comments
 (0)