Procházet zdrojové kódy

Fix CI test stability issues

- Increase extremely short time intervals in ImageCacheTests:
  * Disk cache expiration from 0.01s to 0.1s
  * Memory cache expiration from 0.2s to 0.5s
- Fix missing expectation in RetryStrategyTests.testDelayRetryStrategyDidRetried
- Increase fixed delays in KingfisherManagerTests from 0.1s to 0.3s and 0.2s to 0.5s
- Increase all timeout values from 1s to 3s across multiple test files

These changes improve test reliability in CI environments and slow hardware
by providing more reasonable timing margins for async operations.
onevcat před 7 měsíci
rodič
revize
88a807f84b

+ 3 - 3
Tests/KingfisherTests/ImageCacheTests.swift

@@ -352,7 +352,7 @@ class ImageCacheTests: XCTestCase {
         let exp = expectation(description: #function)
         let exp = expectation(description: #function)
         let key = testKeys[0]
         let key = testKeys[0]
 
 
-        cache.diskStorage.config.expiration = .seconds(0.01)
+        cache.diskStorage.config.expiration = .seconds(0.1)
 
 
         let selfCache = self.cache
         let selfCache = self.cache
         cache.store(testImage, original: testImageData, forKey: key, toDisk: true) { _ in
         cache.store(testImage, original: testImageData, forKey: key, toDisk: true) { _ in
@@ -607,7 +607,7 @@ class ImageCacheTests: XCTestCase {
             testImage,
             testImage,
             original: testImageData,
             original: testImageData,
             forKey: key,
             forKey: key,
-            options: KingfisherParsedOptionsInfo([.memoryCacheExpiration(.seconds(0.2))]),
+            options: KingfisherParsedOptionsInfo([.memoryCacheExpiration(.seconds(0.5))]),
             toDisk: true)
             toDisk: true)
         {
         {
             _ in
             _ in
@@ -626,7 +626,7 @@ class ImageCacheTests: XCTestCase {
             testImage,
             testImage,
             original: testImageData,
             original: testImageData,
             forKey: key,
             forKey: key,
-            options: KingfisherParsedOptionsInfo([.memoryCacheExpiration(.seconds(0.2))]),
+            options: KingfisherParsedOptionsInfo([.memoryCacheExpiration(.seconds(0.5))]),
             toDisk: true
             toDisk: true
         )
         )
         XCTAssertEqual(self.cache.imageCachedType(forKey: key), .memory)
         XCTAssertEqual(self.cache.imageCachedType(forKey: key), .memory)

+ 1 - 1
Tests/KingfisherTests/ImageDataProviderTests.swift

@@ -47,7 +47,7 @@ class ImageDataProviderTests: XCTestCase {
             exp.fulfill()
             exp.fulfill()
         }
         }
 
 
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
     
     
     func testLocalFileImageDataProviderAsync() async {
     func testLocalFileImageDataProviderAsync() async {

+ 3 - 3
Tests/KingfisherTests/ImageViewExtensionTests.swift

@@ -855,7 +855,7 @@ class ImageViewExtensionTests: XCTestCase {
             XCTAssertEqual(result.value!.originalSource.url, brokenURL)
             XCTAssertEqual(result.value!.originalSource.url, brokenURL)
             exp.fulfill()
             exp.fulfill()
         }
         }
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
 
 
     @MainActor func testImageSettingCanCancelAlternativeSource() {
     @MainActor func testImageSettingCanCancelAlternativeSource() {
@@ -893,7 +893,7 @@ class ImageViewExtensionTests: XCTestCase {
             XCTAssertEqual(task.task.originalRequest?.url, url, "Should be the alternative url cancelled.")
             XCTAssertEqual(task.task.originalRequest?.url, url, "Should be the alternative url cancelled.")
         }
         }
 
 
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
 
 
     @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
     @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@@ -917,7 +917,7 @@ class ImageViewExtensionTests: XCTestCase {
             XCTAssertEqual(result.value?.originalSource.url, brokenURL)
             XCTAssertEqual(result.value?.originalSource.url, brokenURL)
             exp.fulfill()
             exp.fulfill()
         }
         }
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
 
 
 }
 }

+ 13 - 13
Tests/KingfisherTests/KingfisherManagerTests.swift

@@ -444,7 +444,7 @@ class KingfisherManagerTests: XCTestCase {
 
 
             XCTAssertEqual(imageCached, .memory)
             XCTAssertEqual(imageCached, .memory)
 
 
-            delay(0.1) {
+            delay(0.3) {
                 manager.cache.clearMemoryCache()
                 manager.cache.clearMemoryCache()
                 
                 
                 imageCached = manager.cache.imageCachedType(forKey: url.cacheKey, processorIdentifier: p.identifier)
                 imageCached = manager.cache.imageCachedType(forKey: url.cacheKey, processorIdentifier: p.identifier)
@@ -735,7 +735,7 @@ class KingfisherManagerTests: XCTestCase {
             // Clear the memory cache.
             // Clear the memory cache.
             self.manager.cache.clearMemoryCache()
             self.manager.cache.clearMemoryCache()
             // After some time, the disk cache should be done.
             // After some time, the disk cache should be done.
-            delay(0.2) {
+            delay(0.5) {
                 XCTAssertEqual(self.manager.cache.imageCachedType(forKey: url.cacheKey), .disk)
                 XCTAssertEqual(self.manager.cache.imageCachedType(forKey: url.cacheKey), .disk)
                 exp.fulfill()
                 exp.fulfill()
             }
             }
@@ -1036,7 +1036,7 @@ class KingfisherManagerTests: XCTestCase {
             exp.fulfill()
             exp.fulfill()
         }
         }
 
 
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
 
 
     func testRetrievingErrorsWithAlternativeSource() {
     func testRetrievingErrorsWithAlternativeSource() {
@@ -1077,7 +1077,7 @@ class KingfisherManagerTests: XCTestCase {
             XCTAssertEqual(errorInfo[2].source.url, url)
             XCTAssertEqual(errorInfo[2].source.url, url)
         }
         }
 
 
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
 
 
     func testRetrievingAlternativeSourceTaskUpdateBlockCalled() {
     func testRetrievingAlternativeSourceTaskUpdateBlockCalled() {
@@ -1110,7 +1110,7 @@ class KingfisherManagerTests: XCTestCase {
 
 
         XCTAssertEqual(task?.sessionTask?.task.currentRequest?.url, brokenURL)
         XCTAssertEqual(task?.sessionTask?.task.currentRequest?.url, brokenURL)
 
 
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
 
 
     func testRetrievingAlternativeSourceCancelled() {
     func testRetrievingAlternativeSourceCancelled() {
@@ -1133,7 +1133,7 @@ class KingfisherManagerTests: XCTestCase {
         }
         }
         task?.cancel()
         task?.cancel()
 
 
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
 
 
     func testRetrievingAlternativeSourceCanCancelUpdatedTask() {
     func testRetrievingAlternativeSourceCanCancelUpdatedTask() {
@@ -1162,7 +1162,7 @@ class KingfisherManagerTests: XCTestCase {
             XCTAssertNotNil(result.error)
             XCTAssertNotNil(result.error)
             XCTAssertTrue(result.error?.isTaskCancelled ?? false)
             XCTAssertTrue(result.error?.isTaskCancelled ?? false)
 
 
-            delay(0.1) {
+            delay(0.3) {
                 _ = dataStub.go()
                 _ = dataStub.go()
                 Task {
                 Task {
                     let result = await called.value
                     let result = await called.value
@@ -1175,7 +1175,7 @@ class KingfisherManagerTests: XCTestCase {
         XCTAssertNotNil(task)
         XCTAssertNotNil(task)
         XCTAssertTrue(task!.isInitialized)
         XCTAssertTrue(task!.isInitialized)
 
 
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
     
     
     func testDownsamplingHandleScale2x() {
     func testDownsamplingHandleScale2x() {
@@ -1203,7 +1203,7 @@ class KingfisherManagerTests: XCTestCase {
             exp.fulfill()
             exp.fulfill()
         }
         }
 
 
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
     
     
     func testDownsamplingHandleScale3x() {
     func testDownsamplingHandleScale3x() {
@@ -1230,7 +1230,7 @@ class KingfisherManagerTests: XCTestCase {
             exp.fulfill()
             exp.fulfill()
         }
         }
 
 
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
 
 
     func testCacheCallbackCoordinatorStateChanging() {
     func testCacheCallbackCoordinatorStateChanging() {
@@ -1315,7 +1315,7 @@ class KingfisherManagerTests: XCTestCase {
         Task {
         Task {
             await task.setValue(t)
             await task.setValue(t)
         }
         }
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
 
 
     func testCanUseCustomizeDefaultCacheSerializer() {
     func testCanUseCustomizeDefaultCacheSerializer() {
@@ -1340,7 +1340,7 @@ class KingfisherManagerTests: XCTestCase {
 
 
                 exp.fulfill()
                 exp.fulfill()
             }
             }
-        waitForExpectations(timeout: 1.0)
+        waitForExpectations(timeout: 3.0)
     }
     }
 
 
     func testCanUseCustomizeDefaultCacheSerializerStoreEncoded() {
     func testCanUseCustomizeDefaultCacheSerializerStoreEncoded() {
@@ -1366,7 +1366,7 @@ class KingfisherManagerTests: XCTestCase {
 
 
                 exp.fulfill()
                 exp.fulfill()
             }
             }
-        waitForExpectations(timeout: 1.0)
+        waitForExpectations(timeout: 3.0)
     }
     }
     
     
     func testImageResultContainsDataWhenDownloaded() {
     func testImageResultContainsDataWhenDownloaded() {

+ 8 - 8
Tests/KingfisherTests/RetryStrategyTests.swift

@@ -99,7 +99,7 @@ class RetryStrategyTests: XCTestCase {
                 exp.fulfill()
                 exp.fulfill()
             }
             }
         )
         )
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
 
 
     func testDelayRetryStrategyExceededCount() {
     func testDelayRetryStrategyExceededCount() {
@@ -155,7 +155,7 @@ class RetryStrategyTests: XCTestCase {
                 exp.fulfill()
                 exp.fulfill()
             }
             }
         }
         }
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
 
 
     func testDelayRetryStrategyNotRetryForErrorReason() {
     func testDelayRetryStrategyNotRetryForErrorReason() {
@@ -208,10 +208,11 @@ class RetryStrategyTests: XCTestCase {
                 exp.fulfill()
                 exp.fulfill()
             }
             }
         }
         }
-        waitForExpectations(timeout: 1, handler: nil)
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
 
 
     func testDelayRetryStrategyDidRetried() {
     func testDelayRetryStrategyDidRetried() {
+        let exp = expectation(description: #function)
         let called = ActorBox(false)
         let called = ActorBox(false)
         let source = Source.network(URL(string: "url")!)
         let source = Source.network(URL(string: "url")!)
         let retry = DelayRetryStrategy(maxRetryCount: 3, retryInterval: .seconds(0))
         let retry = DelayRetryStrategy(maxRetryCount: 3, retryInterval: .seconds(0))
@@ -226,14 +227,13 @@ class RetryStrategyTests: XCTestCase {
             }
             }
             Task {
             Task {
                 await called.setValue(true)
                 await called.setValue(true)
+                let result = await called.value
+                XCTAssertTrue(result)
+                exp.fulfill()
             }
             }
         }
         }
-
-        Task {
-            let result = await called.value
-            XCTAssertTrue(result)
-        }
         
         
+        waitForExpectations(timeout: 3, handler: nil)
     }
     }
 }
 }