|
@@ -585,68 +585,69 @@ class UploadMultipartFormDataTestCase: BaseTestCase {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- func testThatUploadingMultipartFormDataOnBackgroundSessionWritesDataToFileToAvoidCrash() {
|
|
|
|
|
- // Given
|
|
|
|
|
- let manager: Manager = {
|
|
|
|
|
- let identifier = "com.alamofire.uploadtests.\(UUID().uuidString)"
|
|
|
|
|
- let configuration = URLSessionConfiguration.backgroundSessionConfigurationForAllPlatformsWithIdentifier(identifier)
|
|
|
|
|
-
|
|
|
|
|
- return Manager(configuration: configuration, serverTrustPolicyManager: nil)
|
|
|
|
|
- }()
|
|
|
|
|
-
|
|
|
|
|
- let urlString = "https://httpbin.org/post"
|
|
|
|
|
- let french = "français".data(using: String.Encoding.utf8, allowLossyConversion: false)!
|
|
|
|
|
- let japanese = "日本語".data(using: String.Encoding.utf8, allowLossyConversion: false)!
|
|
|
|
|
-
|
|
|
|
|
- let expectation = self.expectation(withDescription: "multipart form data upload should succeed")
|
|
|
|
|
-
|
|
|
|
|
- var request: URLRequest?
|
|
|
|
|
- var response: HTTPURLResponse?
|
|
|
|
|
- var data: Data?
|
|
|
|
|
- var error: NSError?
|
|
|
|
|
- var streamingFromDisk: Bool?
|
|
|
|
|
-
|
|
|
|
|
- // When
|
|
|
|
|
- manager.upload(
|
|
|
|
|
- .POST,
|
|
|
|
|
- urlString,
|
|
|
|
|
- multipartFormData: { multipartFormData in
|
|
|
|
|
- multipartFormData.appendBodyPart(data: french, name: "french")
|
|
|
|
|
- multipartFormData.appendBodyPart(data: japanese, name: "japanese")
|
|
|
|
|
- },
|
|
|
|
|
- encodingCompletion: { result in
|
|
|
|
|
- switch result {
|
|
|
|
|
- case let .success(upload, uploadStreamingFromDisk, _):
|
|
|
|
|
- streamingFromDisk = uploadStreamingFromDisk
|
|
|
|
|
-
|
|
|
|
|
- upload.response { responseRequest, responseResponse, responseData, responseError in
|
|
|
|
|
- request = responseRequest
|
|
|
|
|
- response = responseResponse
|
|
|
|
|
- data = responseData
|
|
|
|
|
- error = responseError
|
|
|
|
|
-
|
|
|
|
|
- expectation.fulfill()
|
|
|
|
|
- }
|
|
|
|
|
- case .failure:
|
|
|
|
|
- expectation.fulfill()
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- waitForExpectations(withTimeout: timeout, handler: nil)
|
|
|
|
|
-
|
|
|
|
|
- // Then
|
|
|
|
|
- XCTAssertNotNil(request, "request should not be nil")
|
|
|
|
|
- XCTAssertNotNil(response, "response should not be nil")
|
|
|
|
|
- XCTAssertNotNil(data, "data should not be nil")
|
|
|
|
|
- XCTAssertNil(error, "error should be nil")
|
|
|
|
|
-
|
|
|
|
|
- if let streamingFromDisk = streamingFromDisk {
|
|
|
|
|
- XCTAssertTrue(streamingFromDisk, "streaming from disk should be true")
|
|
|
|
|
- } else {
|
|
|
|
|
- XCTFail("streaming from disk should not be nil")
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// ⚠️ This test has been removed as a result of rdar://26870455 in Xcode 8 Seed 1
|
|
|
|
|
+// func testThatUploadingMultipartFormDataOnBackgroundSessionWritesDataToFileToAvoidCrash() {
|
|
|
|
|
+// // Given
|
|
|
|
|
+// let manager: Manager = {
|
|
|
|
|
+// let identifier = "com.alamofire.uploadtests.\(UUID().uuidString)"
|
|
|
|
|
+// let configuration = URLSessionConfiguration.backgroundSessionConfigurationForAllPlatformsWithIdentifier(identifier)
|
|
|
|
|
+//
|
|
|
|
|
+// return Manager(configuration: configuration, serverTrustPolicyManager: nil)
|
|
|
|
|
+// }()
|
|
|
|
|
+//
|
|
|
|
|
+// let urlString = "https://httpbin.org/post"
|
|
|
|
|
+// let french = "français".data(using: String.Encoding.utf8, allowLossyConversion: false)!
|
|
|
|
|
+// let japanese = "日本語".data(using: String.Encoding.utf8, allowLossyConversion: false)!
|
|
|
|
|
+//
|
|
|
|
|
+// let expectation = self.expectation(withDescription: "multipart form data upload should succeed")
|
|
|
|
|
+//
|
|
|
|
|
+// var request: URLRequest?
|
|
|
|
|
+// var response: HTTPURLResponse?
|
|
|
|
|
+// var data: Data?
|
|
|
|
|
+// var error: NSError?
|
|
|
|
|
+// var streamingFromDisk: Bool?
|
|
|
|
|
+//
|
|
|
|
|
+// // When
|
|
|
|
|
+// manager.upload(
|
|
|
|
|
+// .POST,
|
|
|
|
|
+// urlString,
|
|
|
|
|
+// multipartFormData: { multipartFormData in
|
|
|
|
|
+// multipartFormData.appendBodyPart(data: french, name: "french")
|
|
|
|
|
+// multipartFormData.appendBodyPart(data: japanese, name: "japanese")
|
|
|
|
|
+// },
|
|
|
|
|
+// encodingCompletion: { result in
|
|
|
|
|
+// switch result {
|
|
|
|
|
+// case let .success(upload, uploadStreamingFromDisk, _):
|
|
|
|
|
+// streamingFromDisk = uploadStreamingFromDisk
|
|
|
|
|
+//
|
|
|
|
|
+// upload.response { responseRequest, responseResponse, responseData, responseError in
|
|
|
|
|
+// request = responseRequest
|
|
|
|
|
+// response = responseResponse
|
|
|
|
|
+// data = responseData
|
|
|
|
|
+// error = responseError
|
|
|
|
|
+//
|
|
|
|
|
+// expectation.fulfill()
|
|
|
|
|
+// }
|
|
|
|
|
+// case .failure:
|
|
|
|
|
+// expectation.fulfill()
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// )
|
|
|
|
|
+//
|
|
|
|
|
+// waitForExpectations(withTimeout: timeout, handler: nil)
|
|
|
|
|
+//
|
|
|
|
|
+// // Then
|
|
|
|
|
+// XCTAssertNotNil(request, "request should not be nil")
|
|
|
|
|
+// XCTAssertNotNil(response, "response should not be nil")
|
|
|
|
|
+// XCTAssertNotNil(data, "data should not be nil")
|
|
|
|
|
+// XCTAssertNil(error, "error should be nil")
|
|
|
|
|
+//
|
|
|
|
|
+// if let streamingFromDisk = streamingFromDisk {
|
|
|
|
|
+// XCTAssertTrue(streamingFromDisk, "streaming from disk should be true")
|
|
|
|
|
+// } else {
|
|
|
|
|
+// XCTFail("streaming from disk should not be nil")
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
// MARK: Combined Test Execution
|
|
// MARK: Combined Test Execution
|
|
|
|
|
|