From 6bf98fb246a0414be87a317c56eba6af114737a2 Mon Sep 17 00:00:00 2001 From: onevcat Date: Tue, 5 May 2015 22:52:52 +0900 Subject: [PATCH 01/13] Log for ci --- KingfisherTests/UIImageViewExtensionTests.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/KingfisherTests/UIImageViewExtensionTests.swift b/KingfisherTests/UIImageViewExtensionTests.swift index a20a39eb2..0368231f1 100644 --- a/KingfisherTests/UIImageViewExtensionTests.swift +++ b/KingfisherTests/UIImageViewExtensionTests.swift @@ -167,6 +167,7 @@ class UIImageViewExtensionTests: XCTestCase { }) { (image, error, cacheType, imageURL) -> () in + println("finished with error: \(error)") XCTAssertTrue(cache1.isImageCachedForKey(URLString).cached, "This image should be cached in cache1.") XCTAssertFalse(cache2.isImageCachedForKey(URLString).cached, "This image should not be cached in cache2.") XCTAssertFalse(KingfisherManager.sharedManager.cache.isImageCachedForKey(URLString).cached, "This image should not be cached in default cache.") From ee8310b945bd76f5f94b90954d6efe2185adc6b1 Mon Sep 17 00:00:00 2001 From: onevcat Date: Tue, 5 May 2015 23:38:00 +0900 Subject: [PATCH 02/13] Log for CI --- KingfisherTests/UIImageViewExtensionTests.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/KingfisherTests/UIImageViewExtensionTests.swift b/KingfisherTests/UIImageViewExtensionTests.swift index 0368231f1..a7bfcbc51 100644 --- a/KingfisherTests/UIImageViewExtensionTests.swift +++ b/KingfisherTests/UIImageViewExtensionTests.swift @@ -175,6 +175,8 @@ class UIImageViewExtensionTests: XCTestCase { self.imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: [.TargetCache: cache2], progressBlock: { (receivedSize, totalSize) -> () in }, completionHandler: { (image, error, cacheType, imageURL) -> () in + + println("finished with error: \(error)") XCTAssertTrue(cache1.isImageCachedForKey(URLString).cached, "This image should be cached in cache1.") XCTAssertTrue(cache2.isImageCachedForKey(URLString).cached, "This image should be cached in cache2.") XCTAssertFalse(KingfisherManager.sharedManager.cache.isImageCachedForKey(URLString).cached, "This image should not be cached in default cache.") From 165306afd19420619df6b7ad194514f936cc8b4c Mon Sep 17 00:00:00 2001 From: onevcat Date: Tue, 5 May 2015 23:47:51 +0900 Subject: [PATCH 03/13] Add log for ci --- Kingfisher/ImageCache.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Kingfisher/ImageCache.swift b/Kingfisher/ImageCache.swift index f46df052b..c38fef628 100644 --- a/Kingfisher/ImageCache.swift +++ b/Kingfisher/ImageCache.swift @@ -513,11 +513,16 @@ public extension ImageCache { :returns: The check result. */ public func isImageCachedForKey(key: String) -> CacheCheckResult { + + println("isImageCachedForKey? \(key)") + if memoryCache.objectForKey(key) != nil { return CacheCheckResult(cached: true, cacheType: .Memory) } let filePath = cachePathForKey(key) + println("filePath? \(filePath)") + if fileManager.fileExistsAtPath(filePath) { return CacheCheckResult(cached: true, cacheType: .Disk) } From c43252fd72ca45765532bd974b02b086cbe710dc Mon Sep 17 00:00:00 2001 From: onevcat Date: Wed, 6 May 2015 00:04:07 +0900 Subject: [PATCH 04/13] Update time duration for CI --- KingfisherTests/ImageCacheTests.swift | 16 ++++++++-------- KingfisherTests/ImageDownloaderTests.swift | 12 ++++++------ KingfisherTests/UIButtonExtensionTests.swift | 4 ++-- KingfisherTests/UIImageViewExtensionTests.swift | 8 ++++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/KingfisherTests/ImageCacheTests.swift b/KingfisherTests/ImageCacheTests.swift index 2c67ae285..99e6ac816 100644 --- a/KingfisherTests/ImageCacheTests.swift +++ b/KingfisherTests/ImageCacheTests.swift @@ -83,7 +83,7 @@ class ImageCacheTests: XCTestCase { expectation.fulfill() } } - waitForExpectationsWithTimeout(1, handler:nil) + waitForExpectationsWithTimeout(5, handler:nil) } func testClearMemoryCache() { @@ -97,7 +97,7 @@ class ImageCacheTests: XCTestCase { }) } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } func testNoImageFound() { @@ -111,7 +111,7 @@ class ImageCacheTests: XCTestCase { return } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } func testStoreImageInMemory() { @@ -125,7 +125,7 @@ class ImageCacheTests: XCTestCase { return } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } func testStoreMultipleImages() { @@ -141,7 +141,7 @@ class ImageCacheTests: XCTestCase { expectation.fulfill() } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } func testIsImageCachedForKey() { @@ -153,7 +153,7 @@ class ImageCacheTests: XCTestCase { expectation.fulfill() } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } func testRetrivingImagePerformance() { @@ -169,7 +169,7 @@ class ImageCacheTests: XCTestCase { expectation.fulfill() } - self.waitForExpectationsWithTimeout(15, handler: nil) + self.waitForExpectationsWithTimeout(20, handler: nil) } func testCleanDiskCacheNotification() { @@ -194,7 +194,7 @@ class ImageCacheTests: XCTestCase { self.cache.cleanExpiredDiskCache() } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } // MARK: - Helper diff --git a/KingfisherTests/ImageDownloaderTests.swift b/KingfisherTests/ImageDownloaderTests.swift index d268c4270..9130ec9ee 100644 --- a/KingfisherTests/ImageDownloaderTests.swift +++ b/KingfisherTests/ImageDownloaderTests.swift @@ -69,7 +69,7 @@ class ImageDownloaderTests: XCTestCase { XCTAssert(image != nil, "Download should be able to finished for URL: \(imageURL)") } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } func testDownloadMultipleImages() { @@ -94,7 +94,7 @@ class ImageDownloaderTests: XCTestCase { expectation.fulfill() } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } func testDownloadAnImageWithMultipleCallback() { @@ -119,7 +119,7 @@ class ImageDownloaderTests: XCTestCase { expectation.fulfill() } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } func testDownloadWithModifyingRequest() { @@ -141,7 +141,7 @@ class ImageDownloaderTests: XCTestCase { XCTAssertEqual(imageURL!, NSURL(string: URLString)!, "The returned imageURL should be the replaced one") expectation.fulfill() } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } func testServerNotModifiedResponse() { @@ -157,7 +157,7 @@ class ImageDownloaderTests: XCTestCase { XCTAssertEqual(error!.code, KingfisherError.NotModified.rawValue, "The error should be NotModified.") expectation.fulfill() } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } // Since we could not receive one challage, no test for trusted hosts currently. @@ -176,7 +176,7 @@ class ImageDownloaderTests: XCTestCase { LSNocilla.sharedInstance().start() }) - waitForExpectationsWithTimeout(10) { (error) in + waitForExpectationsWithTimeout(20) { (error) in XCTAssertNil(error, "\(error)") LSNocilla.sharedInstance().start() } diff --git a/KingfisherTests/UIButtonExtensionTests.swift b/KingfisherTests/UIButtonExtensionTests.swift index c796264d0..0dc271161 100644 --- a/KingfisherTests/UIButtonExtensionTests.swift +++ b/KingfisherTests/UIButtonExtensionTests.swift @@ -79,7 +79,7 @@ class UIButtonExtensionTests: XCTestCase { XCTAssert(self.button.kf_webURLForState(UIControlState.Highlighted) == imageURL, "Web URL should equal to the downloaded url.") XCTAssert(cacheType == .None, "cacheType should be .None since the image was just downloaded.") } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } func testDownloadAndSetBackgroundImage() { @@ -103,6 +103,6 @@ class UIButtonExtensionTests: XCTestCase { XCTAssert(cacheType == .None, "cacheType should be .None since the image was just downloaded.") } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } } diff --git a/KingfisherTests/UIImageViewExtensionTests.swift b/KingfisherTests/UIImageViewExtensionTests.swift index a7bfcbc51..316f7d8b7 100644 --- a/KingfisherTests/UIImageViewExtensionTests.swift +++ b/KingfisherTests/UIImageViewExtensionTests.swift @@ -82,7 +82,7 @@ class UIImageViewExtensionTests: XCTestCase { XCTAssert(cacheType == .None, "The cache type should be none here. This image was just downloaded.") } - waitForExpectationsWithTimeout(1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } func testImageDownloadCancelForImageView() { @@ -108,7 +108,7 @@ class UIImageViewExtensionTests: XCTestCase { XCTAssert(completionBlockIsCalled == false, "CompletionBlock should not be called since it is canceled.") } - waitForExpectationsWithTimeout(0.1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } func testImageDownloadCacelPartialTask() { @@ -149,7 +149,7 @@ class UIImageViewExtensionTests: XCTestCase { XCTAssert(task3Completion == true, "Task 3 should be completed.") } - waitForExpectationsWithTimeout(0.1, handler: nil) + waitForExpectationsWithTimeout(5, handler: nil) } func testImageDownalodMultipleCaches() { @@ -188,7 +188,7 @@ class UIImageViewExtensionTests: XCTestCase { } - waitForExpectationsWithTimeout(0.1, handler: { (error) -> Void in + waitForExpectationsWithTimeout(5, handler: { (error) -> Void in clearCaches([cache1, cache2]) }) } From 889d428f7df847fbc2f248a2aa7f94c765bc2307 Mon Sep 17 00:00:00 2001 From: onevcat Date: Wed, 6 May 2015 00:11:55 +0900 Subject: [PATCH 05/13] Fix order of cache. --- Kingfisher/KingfisherManager.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Kingfisher/KingfisherManager.swift b/Kingfisher/KingfisherManager.swift index e92e188dc..5f59550a3 100644 --- a/Kingfisher/KingfisherManager.swift +++ b/Kingfisher/KingfisherManager.swift @@ -192,10 +192,11 @@ public class KingfisherManager { return } - completionHandler?(image: image, error: error, cacheType: .None, imageURL: URL) if let image = image { targetCache.storeImage(image, forKey: key, toDisk: !options.cacheMemoryOnly, completionHandler: nil) } + + completionHandler?(image: image, error: error, cacheType: .None, imageURL: URL) } } } From cdb6c8d1fbfaf908fbed7f0ad1a45cf26a797d35 Mon Sep 17 00:00:00 2001 From: onevcat Date: Wed, 6 May 2015 00:16:02 +0900 Subject: [PATCH 06/13] Log --- KingfisherTests/ImageCacheTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KingfisherTests/ImageCacheTests.swift b/KingfisherTests/ImageCacheTests.swift index 99e6ac816..aaf864f52 100644 --- a/KingfisherTests/ImageCacheTests.swift +++ b/KingfisherTests/ImageCacheTests.swift @@ -74,7 +74,7 @@ class ImageCacheTests: XCTestCase { cache.storeImage(testImage, forKey: testKeys[0], toDisk: true) { () -> () in let files = NSFileManager.defaultManager().contentsOfDirectoryAtPath(diskCachePath, error:nil) - XCTAssert(files?.count == 1, "Should be 1 file at the path") + XCTAssert(files?.count == 1, "Should be 1 file at the path. Actual: \(files?.count) | \(files)") self.cache.clearDiskCacheWithCompletionHandler { () -> () in From 74462b8f18bb857bc4a5b9626323fe990e60026f Mon Sep 17 00:00:00 2001 From: onevcat Date: Wed, 6 May 2015 00:20:37 +0900 Subject: [PATCH 07/13] Remove log --- Kingfisher/ImageCache.swift | 3 --- KingfisherTests/UIImageViewExtensionTests.swift | 2 -- 2 files changed, 5 deletions(-) diff --git a/Kingfisher/ImageCache.swift b/Kingfisher/ImageCache.swift index c38fef628..6197da422 100644 --- a/Kingfisher/ImageCache.swift +++ b/Kingfisher/ImageCache.swift @@ -514,14 +514,11 @@ public extension ImageCache { */ public func isImageCachedForKey(key: String) -> CacheCheckResult { - println("isImageCachedForKey? \(key)") - if memoryCache.objectForKey(key) != nil { return CacheCheckResult(cached: true, cacheType: .Memory) } let filePath = cachePathForKey(key) - println("filePath? \(filePath)") if fileManager.fileExistsAtPath(filePath) { return CacheCheckResult(cached: true, cacheType: .Disk) diff --git a/KingfisherTests/UIImageViewExtensionTests.swift b/KingfisherTests/UIImageViewExtensionTests.swift index 316f7d8b7..6499abf3b 100644 --- a/KingfisherTests/UIImageViewExtensionTests.swift +++ b/KingfisherTests/UIImageViewExtensionTests.swift @@ -167,7 +167,6 @@ class UIImageViewExtensionTests: XCTestCase { }) { (image, error, cacheType, imageURL) -> () in - println("finished with error: \(error)") XCTAssertTrue(cache1.isImageCachedForKey(URLString).cached, "This image should be cached in cache1.") XCTAssertFalse(cache2.isImageCachedForKey(URLString).cached, "This image should not be cached in cache2.") XCTAssertFalse(KingfisherManager.sharedManager.cache.isImageCachedForKey(URLString).cached, "This image should not be cached in default cache.") @@ -176,7 +175,6 @@ class UIImageViewExtensionTests: XCTestCase { }, completionHandler: { (image, error, cacheType, imageURL) -> () in - println("finished with error: \(error)") XCTAssertTrue(cache1.isImageCachedForKey(URLString).cached, "This image should be cached in cache1.") XCTAssertTrue(cache2.isImageCachedForKey(URLString).cached, "This image should be cached in cache2.") XCTAssertFalse(KingfisherManager.sharedManager.cache.isImageCachedForKey(URLString).cached, "This image should not be cached in default cache.") From 44302251f99af3948a9269aeddf1eb3a1189510f Mon Sep 17 00:00:00 2001 From: onevcat Date: Wed, 6 May 2015 00:28:46 +0900 Subject: [PATCH 08/13] Fix clear cache test --- KingfisherTests/ImageCacheTests.swift | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/KingfisherTests/ImageCacheTests.swift b/KingfisherTests/ImageCacheTests.swift index aaf864f52..db8b95e96 100644 --- a/KingfisherTests/ImageCacheTests.swift +++ b/KingfisherTests/ImageCacheTests.swift @@ -73,14 +73,21 @@ class ImageCacheTests: XCTestCase { cache.storeImage(testImage, forKey: testKeys[0], toDisk: true) { () -> () in - let files = NSFileManager.defaultManager().contentsOfDirectoryAtPath(diskCachePath, error:nil) - XCTAssert(files?.count == 1, "Should be 1 file at the path. Actual: \(files?.count) | \(files)") - - self.cache.clearDiskCacheWithCompletionHandler { () -> () in + let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.5 * Double(NSEC_PER_SEC))) + dispatch_after(delayTime, dispatch_get_main_queue()) { let files = NSFileManager.defaultManager().contentsOfDirectoryAtPath(diskCachePath, error:nil) - XCTAssert(files?.count == 0, "Files should be at deleted") - expectation.fulfill() + XCTAssert(files?.count == 1, "Should be 1 file at the path. Actual: \(files?.count) | \(files)") + + self.cache.clearDiskCacheWithCompletionHandler { () -> () in + + let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.5 * Double(NSEC_PER_SEC))) + dispatch_after(delayTime, dispatch_get_main_queue()) { + let files = NSFileManager.defaultManager().contentsOfDirectoryAtPath(diskCachePath, error:nil) + XCTAssert(files?.count == 0, "Files should be at deleted") + expectation.fulfill() + } + } } } waitForExpectationsWithTimeout(5, handler:nil) From a5b174f8f7be7d13f8b0816a301fe32db36391d5 Mon Sep 17 00:00:00 2001 From: onevcat Date: Wed, 6 May 2015 00:50:06 +0900 Subject: [PATCH 09/13] Clear memory cache too. --- KingfisherTests/ImageCacheTests.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/KingfisherTests/ImageCacheTests.swift b/KingfisherTests/ImageCacheTests.swift index db8b95e96..942e576e3 100644 --- a/KingfisherTests/ImageCacheTests.swift +++ b/KingfisherTests/ImageCacheTests.swift @@ -45,6 +45,7 @@ class ImageCacheTests: XCTestCase { override func tearDown() { // Put teardown code here. This method is called after the invocation of each test method in the class. super.tearDown() + cache.clearMemoryCache() cache.clearDiskCache() cache = nil observer = nil From 442b2448f9fcca033b82d4c35871a515bb2a9c75 Mon Sep 17 00:00:00 2001 From: onevcat Date: Wed, 6 May 2015 00:58:49 +0900 Subject: [PATCH 10/13] Wait for clean. --- KingfisherTests/ImageCacheTests.swift | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/KingfisherTests/ImageCacheTests.swift b/KingfisherTests/ImageCacheTests.swift index 942e576e3..1ea60500d 100644 --- a/KingfisherTests/ImageCacheTests.swift +++ b/KingfisherTests/ImageCacheTests.swift @@ -153,15 +153,17 @@ class ImageCacheTests: XCTestCase { } func testIsImageCachedForKey() { - XCTAssert(cache.isImageCachedForKey(testKeys[0]).cached == false, "This image should not be cached yet.") - - let expectation = expectationWithDescription("wait for caching image") - cache.storeImage(testImage, forKey: testKeys[0], toDisk: true) { () -> () in - XCTAssert(self.cache.isImageCachedForKey(testKeys[0]).cached == true, "This image should be already cached.") - expectation.fulfill() - } + let expectation = self.expectationWithDescription("wait for caching image") - waitForExpectationsWithTimeout(5, handler: nil) + let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.5 * Double(NSEC_PER_SEC))) + dispatch_after(delayTime, dispatch_get_main_queue()) { + XCTAssert(self.cache.isImageCachedForKey(testKeys[0]).cached == false, "This image should not be cached yet.") + self.cache.storeImage(testImage, forKey: testKeys[0], toDisk: true) { () -> () in + XCTAssert(self.cache.isImageCachedForKey(testKeys[0]).cached == true, "This image should be already cached.") + expectation.fulfill() + } + } + self.waitForExpectationsWithTimeout(5, handler: nil) } func testRetrivingImagePerformance() { From 7fb4ff31cf10ebe3ebbb1d99947234ee15e4ff95 Mon Sep 17 00:00:00 2001 From: onevcat Date: Wed, 6 May 2015 01:17:46 +0900 Subject: [PATCH 11/13] New commit for testing CI --- KingfisherTests/ImageCacheTests.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/KingfisherTests/ImageCacheTests.swift b/KingfisherTests/ImageCacheTests.swift index 1ea60500d..0bc241035 100644 --- a/KingfisherTests/ImageCacheTests.swift +++ b/KingfisherTests/ImageCacheTests.swift @@ -169,7 +169,6 @@ class ImageCacheTests: XCTestCase { func testRetrivingImagePerformance() { let expectation = self.expectationWithDescription("wait for retriving image") - self.cache.storeImage(testImage, forKey: testKeys[0], toDisk: true) { () -> () in self.measureBlock({ () -> Void in for _ in 1 ..< 1000 { From d5b382a456e3cc9420ddce847e01dce4efff03f1 Mon Sep 17 00:00:00 2001 From: onevcat Date: Wed, 6 May 2015 01:42:01 +0900 Subject: [PATCH 12/13] Fix waiting time --- KingfisherTests/ImageCacheTests.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/KingfisherTests/ImageCacheTests.swift b/KingfisherTests/ImageCacheTests.swift index 0bc241035..c3e2654a7 100644 --- a/KingfisherTests/ImageCacheTests.swift +++ b/KingfisherTests/ImageCacheTests.swift @@ -74,7 +74,7 @@ class ImageCacheTests: XCTestCase { cache.storeImage(testImage, forKey: testKeys[0], toDisk: true) { () -> () in - let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.5 * Double(NSEC_PER_SEC))) + let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(1 * Double(NSEC_PER_SEC))) dispatch_after(delayTime, dispatch_get_main_queue()) { let files = NSFileManager.defaultManager().contentsOfDirectoryAtPath(diskCachePath, error:nil) @@ -82,7 +82,7 @@ class ImageCacheTests: XCTestCase { self.cache.clearDiskCacheWithCompletionHandler { () -> () in - let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.5 * Double(NSEC_PER_SEC))) + let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(1 * Double(NSEC_PER_SEC))) dispatch_after(delayTime, dispatch_get_main_queue()) { let files = NSFileManager.defaultManager().contentsOfDirectoryAtPath(diskCachePath, error:nil) XCTAssert(files?.count == 0, "Files should be at deleted") @@ -91,7 +91,7 @@ class ImageCacheTests: XCTestCase { } } } - waitForExpectationsWithTimeout(5, handler:nil) + waitForExpectationsWithTimeout(10, handler:nil) } func testClearMemoryCache() { From 4dcf5638573376fb3c4753e1b523da40026591da Mon Sep 17 00:00:00 2001 From: onevcat Date: Wed, 6 May 2015 11:36:28 +0900 Subject: [PATCH 13/13] Fix testcase for ci --- KingfisherTests/ImageCacheTests.swift | 28 +++++++++++---------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/KingfisherTests/ImageCacheTests.swift b/KingfisherTests/ImageCacheTests.swift index c3e2654a7..95451f6e6 100644 --- a/KingfisherTests/ImageCacheTests.swift +++ b/KingfisherTests/ImageCacheTests.swift @@ -71,24 +71,18 @@ class ImageCacheTests: XCTestCase { let diskCachePath = paths.first!.stringByAppendingPathComponent(cacheName) let expectation = expectationWithDescription("wait for clearing disk cache") + let key = testKeys[0] - cache.storeImage(testImage, forKey: testKeys[0], toDisk: true) { () -> () in - - let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(1 * Double(NSEC_PER_SEC))) - dispatch_after(delayTime, dispatch_get_main_queue()) { - - let files = NSFileManager.defaultManager().contentsOfDirectoryAtPath(diskCachePath, error:nil) - XCTAssert(files?.count == 1, "Should be 1 file at the path. Actual: \(files?.count) | \(files)") - - self.cache.clearDiskCacheWithCompletionHandler { () -> () in - - let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(1 * Double(NSEC_PER_SEC))) - dispatch_after(delayTime, dispatch_get_main_queue()) { - let files = NSFileManager.defaultManager().contentsOfDirectoryAtPath(diskCachePath, error:nil) - XCTAssert(files?.count == 0, "Files should be at deleted") - expectation.fulfill() - } - } + cache.storeImage(testImage, forKey: key, toDisk: true) { () -> () in + self.cache.clearMemoryCache() + let cacheResult = self.cache.isImageCachedForKey(key) + XCTAssertTrue(cacheResult.cached, "Should be cached") + XCTAssert(cacheResult.cacheType == .Disk, "Should be cached in disk") + + self.cache.clearDiskCacheWithCompletionHandler { () -> () in + let cacheResult = self.cache.isImageCachedForKey(key) + XCTAssertFalse(cacheResult.cached, "Should be not cached") + expectation.fulfill() } } waitForExpectationsWithTimeout(10, handler:nil)