فهرست منبع

Improve stability of memory cache or refresh test

onevcat 7 سال پیش
والد
کامیت
9220cc3797
1فایلهای تغییر یافته به همراه17 افزوده شده و 14 حذف شده
  1. 17 14
      Tests/KingfisherTests/KingfisherManagerTests.swift

+ 17 - 14
Tests/KingfisherTests/KingfisherManagerTests.swift

@@ -467,23 +467,26 @@ class KingfisherManagerTests: XCTestCase {
 
         let url = URL(string: URLString)!
 
-        manager.retrieveImage(with: url, options: [.fromMemoryCacheOrRefresh], progressBlock: nil) {
-            image, _, type, _ in
-            // Can download and cache normally
-            XCTAssertNotNil(image)
-            XCTAssertEqual(type, .none)
-
-            // Can still be got from memory even when disk cache cleared.
-            self.manager.cache.clearDiskCache {
-                self.manager.retrieveImage(with: url, options: [.fromMemoryCacheOrRefresh], progressBlock: nil) {
-                    image, _, type, _ in
-                    XCTAssertNotNil(image)
-                    XCTAssertEqual(type, .memory)
-
-                    expectation.fulfill()
+        delay(0.1) { // Wait for disk cache cleaning
+            self.manager.retrieveImage(with: url, options: [.fromMemoryCacheOrRefresh], progressBlock: nil) {
+                image, _, type, _ in
+                // Can download and cache normally
+                XCTAssertNotNil(image)
+                XCTAssertEqual(type, .none)
+                
+                // Can still be got from memory even when disk cache cleared.
+                self.manager.cache.clearDiskCache {
+                    self.manager.retrieveImage(with: url, options: [.fromMemoryCacheOrRefresh], progressBlock: nil) {
+                        image, _, type, _ in
+                        XCTAssertNotNil(image)
+                        XCTAssertEqual(type, .memory)
+                        
+                        expectation.fulfill()
+                    }
                 }
             }
         }
+        
         waitForExpectations(timeout: 5, handler: nil)
     }