                 task1Completion = true
         }
         
+        let _ = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+            
+            }) { (image, error, cacheType, imageURL) -> () in
+                task2Completion = true
+        }
+        
+        let _ = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+            
+            }) { (image, error, cacheType, imageURL) -> () in
+                task3Completion = true
+        }
+        
+        task1.cancel()
+        
+        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(Double(NSEC_PER_SEC) * 0.09)), dispatch_get_main_queue()) { () -> Void in
+            expectation.fulfill()
+            XCTAssert(task1Completion == false, "Task 1 is canceled. The completion flag should be fasle.")
+            XCTAssert(task2Completion == true, "Task 2 should be completed.")
+            XCTAssert(task3Completion == true, "Task 3 should be completed.")
+        }
+        
+        waitForExpectationsWithTimeout(5, handler: nil)
+    }
+    
+    func testImageDownloadCancelPartialTaskAfterRequestStarted() {
+        let expectation = expectationWithDescription("wait for downloading image")
+        
+        let URLString = testKeys[0]
+        let stub = stubRequest("GET", URLString).andReturn(200).withBody(testImageData).delay()
+        let URL = NSURL(string: URLString)!
+        
+        var task1Completion = false
+        var task2Completion = false
+        var task3Completion = false
+        
+        let task1 = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+            
+            }) { (image, error, cacheType, imageURL) -> () in
+                task1Completion = true
+        }
+        
         let task2 = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
             }) { (image, error, cacheType, imageURL) -> () in

        waitForExpectationsWithTimeout(5, handler: nil)
    }
    
    func testImageDownloadCancelPartialTaskAfterRequestStarted() {
        let expectation = expectationWithDescription("wait for downloading image")
        
        let URLString = testKeys[0]
        let stub = stubRequest("GET", URLString).andReturn(200).withBody(testImageData).delay()
        let URL = NSURL(string: URLString)!
        
        var task1Completion = false
        var task2Completion = false
        var task3Completion = false
        
        let task1 = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
            
            }) { (image, error, cacheType, imageURL) -> () in
                task1Completion = true
        }
        
        let task2 = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
            
            }) { (image, error, cacheType, imageURL) -> () in
                task2Completion = true
        }
        
        let task3 = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
            
            }) { (image, error, cacheType, imageURL) -> () in
                task3Completion = true
        }
        
        // Prevent unused warning.
        print(task2)
        print(task3)
        
        dispatch_async(dispatch_get_main_queue()) { () -> Void in
            task1.cancel()
            stub.go()
        }
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(Double(NSEC_PER_SEC) * 0.09)), dispatch_get_main_queue()) { () -> Void in
            expectation.fulfill()
            XCTAssert(task1Completion == false, "Task 1 is canceled. The completion flag should be fasle.")
            XCTAssert(task2Completion == true, "Task 2 should be completed.")
            XCTAssert(task3Completion == true, "Task 3 should be completed.")
        }
        
        waitForExpectationsWithTimeout(5, handler: nil)
    }
    
    func testImageDownalodMultipleCaches() {
        
        let cache1 = ImageCache(name: "cache1")

        print(task2)
        print(task3)
        
        dispatch_async(dispatch_get_main_queue()) { () -> Void in
            task1.cancel()
            stub.go()
        }
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(Double(NSEC_PER_SEC) * 0.09)), dispatch_get_main_queue()) { () -> Void in
            expectation.fulfill()
