Forráskód Böngészése

Changing upload and download tests to cancel after first progress block call to ensure that fulfill is called at most once

Mattt Thompson 11 éve
szülő
commit
c1519a5007
2 módosított fájl, 18 hozzáadás és 14 törlés
  1. 9 7
      Tests/DownloadTests.swift
  2. 9 7
      Tests/UploadTests.swift

+ 9 - 7
Tests/DownloadTests.swift

@@ -87,14 +87,16 @@ class AlamofireDownloadResponseTestCase: XCTestCase {
 
         let destination = Alamofire.Request.suggestedDownloadDestination(directory: searchPathDirectory, domain: searchPathDomain)
 
-        Alamofire.download(.GET, URL, destination)
-                 .progress { (bytesRead, totalBytesRead, totalBytesExpectedToRead) -> Void in
-                    expectation.fulfill()
+        let download = Alamofire.download(.GET, URL, destination)
+        download.progress { (bytesRead, totalBytesRead, totalBytesExpectedToRead) -> Void in
+            expectation.fulfill()
+
+            XCTAssertGreaterThan(bytesRead, 0, "bytesRead should be > 0")
+            XCTAssertGreaterThan(totalBytesRead, 0, "totalBytesRead should be > 0")
+            XCTAssertEqual(totalBytesExpectedToRead, -1, "totalBytesExpectedToRead should be -1")
 
-                    XCTAssertGreaterThan(bytesRead, 0, "bytesRead should be > 0")
-                    XCTAssertGreaterThan(totalBytesRead, 0, "totalBytesRead should be > 0")
-                    XCTAssertEqual(totalBytesExpectedToRead, -1, "totalBytesExpectedToRead should be -1")
-                 }
+            download.cancel()
+        }
 
         waitForExpectationsWithTimeout(10) { (error) in
             XCTAssertNil(error, "\(error)")

+ 9 - 7
Tests/UploadTests.swift

@@ -51,14 +51,16 @@ class UploadResponseTestCase: XCTestCase {
 
         let expectation = expectationWithDescription(URL)
 
-        Alamofire.upload(.POST, URL, data!)
-                 .progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) -> Void in
-                    expectation.fulfill()
+        let upload = Alamofire.upload(.POST, URL, data!)
+        upload.progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) -> Void in
+            expectation.fulfill()
 
-                    XCTAssertGreaterThan(bytesWritten, 0, "bytesWritten should be > 0")
-                    XCTAssertGreaterThan(totalBytesWritten, 0, "totalBytesWritten should be > 0")
-                    XCTAssertGreaterThan(totalBytesExpectedToWrite, 0, "totalBytesExpectedToWrite should be > 0")
-                 }
+            XCTAssertGreaterThan(bytesWritten, 0, "bytesWritten should be > 0")
+            XCTAssertGreaterThan(totalBytesWritten, 0, "totalBytesWritten should be > 0")
+            XCTAssertGreaterThan(totalBytesExpectedToWrite, 0, "totalBytesExpectedToWrite should be > 0")
+
+            upload.cancel()
+        }
 
         waitForExpectationsWithTimeout(10) { (error) in
             XCTAssertNil(error, "\(error)")