Explorar o código

Make test more robust

onevcat %!s(int64=7) %!d(string=hai) anos
pai
achega
d9b197a5d3

+ 5 - 5
Sources/Networking/ImageDownloader.swift

@@ -175,11 +175,11 @@ open class ImageDownloader {
     ///                        defined in `.callbackQueue` in `options` parameter.
     /// - Returns: A downloading task. You could call `cancel` on it to stop the download task.
     @discardableResult
-    open func downloadImage(with url: URL,
-                            options: KingfisherOptionsInfo? = nil,
-                            progressBlock: DownloadProgressBlock? = nil,
-                            completionHandler: ((Result<ImageDownloadResult, KingfisherError>) -> Void)? = nil)
-        -> DownloadTask?
+    open func downloadImage(
+        with url: URL,
+        options: KingfisherOptionsInfo? = nil,
+        progressBlock: DownloadProgressBlock? = nil,
+        completionHandler: ((Result<ImageDownloadResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
     {
         // Creates default request.
         var request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: downloadTimeout)

+ 3 - 1
Tests/KingfisherTests/ImageDownloaderTests.swift

@@ -430,7 +430,7 @@ class ImageDownloaderTests: XCTestCase {
     func testDownloadWithDifferentProcessors() {
         let exp = expectation(description: #function)
         let url = testURLs[0]
-        stub(url, data: testImageData)
+        let stub = delayedStub(url, data: testImageData)
 
         let p1 = RoundCornerImageProcessor(cornerRadius: 40)
         let roundcornered = testImage.kf.image(withRoundRadius: 40, fit: testImage.kf.size)
@@ -455,6 +455,8 @@ class ImageDownloaderTests: XCTestCase {
         XCTAssertNotNil(task1)
         XCTAssertEqual(task1?.sessionTask.task, task2?.sessionTask.task)
 
+        _ = stub.go()
+        
         group.notify(queue: .main, execute: exp.fulfill)
         waitForExpectations(timeout: 1, handler: nil)
     }