Parcourir la source

Merge pull request #1448 from onevcat/fix/testing-stability

Loose some time sensitive tests
Wei Wang il y a 5 ans
Parent
commit
06f79ce981

+ 3 - 3
Tests/KingfisherTests/DiskStorageTests.swift

@@ -96,7 +96,7 @@ class DiskStorageTests: XCTestCase {
         try! storage.store(value: "1", forKey: "1", expiration: .seconds(1))
 
         XCTAssertTrue(storage.isCached(forKey: "1", referenceDate: now))
-        XCTAssertFalse(storage.isCached(forKey: "1", referenceDate: now.addingTimeInterval(2)))
+        XCTAssertFalse(storage.isCached(forKey: "1", referenceDate: now.addingTimeInterval(5)))
     }
 
     func testConfigExpiration() {
@@ -106,7 +106,7 @@ class DiskStorageTests: XCTestCase {
         storage.config.expiration = .seconds(1)
         try! storage.store(value: "1", forKey: "1")
         XCTAssertTrue(storage.isCached(forKey: "1", referenceDate: now))
-        XCTAssertFalse(storage.isCached(forKey: "1", referenceDate: now.addingTimeInterval(2)))
+        XCTAssertFalse(storage.isCached(forKey: "1", referenceDate: now.addingTimeInterval(5)))
     }
 
     func testExtendExpirationByAccessing() {
@@ -115,7 +115,7 @@ class DiskStorageTests: XCTestCase {
         let now = Date()
         try! storage.store(value: "1", forKey: "1", expiration: .seconds(2))
         XCTAssertTrue(storage.isCached(forKey: "1"))
-        XCTAssertFalse(storage.isCached(forKey: "1", referenceDate: now.addingTimeInterval(3)))
+        XCTAssertFalse(storage.isCached(forKey: "1", referenceDate: now.addingTimeInterval(5)))
 
         delay(1) {
             let v = try! self.storage.value(forKey: "1")

+ 1 - 1
Tests/KingfisherTests/ImageCacheTests.swift

@@ -288,7 +288,7 @@ class ImageCacheTests: XCTestCase {
                 self.cache.cleanExpiredDiskCache()
             }
         }
-        waitForExpectations(timeout: 2, handler: nil)
+        waitForExpectations(timeout: 5, handler: nil)
     }
     
     func testCannotRetrieveCacheWithProcessorIdentifier() {

+ 3 - 5
Tests/KingfisherTests/KingfisherManagerTests.swift

@@ -422,7 +422,7 @@ class KingfisherManagerTests: XCTestCase {
                 exp.fulfill()
             }
         }
-        waitForExpectations(timeout: 3, handler: nil)
+        waitForExpectations(timeout: 5, handler: nil)
     }
     
     func testCouldProcessOnOriginalImageWithOriginalCache() {
@@ -496,12 +496,10 @@ class KingfisherManagerTests: XCTestCase {
             // We are not waiting for cache finishing here. So only sync memory cache is done.
             XCTAssertEqual(self.manager.cache.imageCachedType(forKey: url.cacheKey), .memory)
             
-            // Once we clear the memory cache, it will be .none (Disk caching operation is not started yet.)
+            // Clear the memory cache.
             self.manager.cache.clearMemoryCache()
-            XCTAssertEqual(self.manager.cache.imageCachedType(forKey: url.cacheKey), .none)
-            
             // After some time, the disk cache should be done.
-            delay(0.1) {
+            delay(0.2) {
                 XCTAssertEqual(self.manager.cache.imageCachedType(forKey: url.cacheKey), .disk)
                 exp.fulfill()
             }

+ 2 - 2
Tests/KingfisherTests/MemoryStorageTests.swift

@@ -262,7 +262,7 @@ class MemoryStorageTests: XCTestCase {
         XCTAssertEqual(
             obj.estimatedExpiration.timeIntervalSince1970,
             now.addingTimeInterval(1).timeIntervalSince1970,
-            accuracy: 0.2)
+            accuracy: 0.3)
 
         let exp = expectation(description: #function)
         delay(0.5) {
@@ -270,7 +270,7 @@ class MemoryStorageTests: XCTestCase {
             XCTAssertEqual(
                 obj.estimatedExpiration.timeIntervalSince1970,
                 now.addingTimeInterval(1.5).timeIntervalSince1970,
-                accuracy: 0.2)
+                accuracy: 0.3)
             exp.fulfill()
         }
         waitForExpectations(timeout: 3, handler: nil)