in OSSSwiftDemo/OSSSwiftDemoTests/OSSMultipartUploadTests.swift [79:106]
func testAPI_cancelMultipartUpload() {
let fileURL = Bundle.main.url(forResource: "wangwang", withExtension: "zip")
let request = OSSMultipartUploadRequest()
request.uploadingFileURL = fileURL!
request.bucketName = OSS_BUCKET_PRIVATE
request.objectKey = "wangwangForSwift.zip"
request.partSize = 512000
request.uploadProgress = { (bytesSend, totoalBytesSend, totalBytesExpectedToSend) -> Void in
OSSLogVerbose("bytesSend: \(bytesSend), totoalBytesSend: \(totoalBytesSend), totalBytesExpectedToSend: \(totalBytesExpectedToSend)")
}
let tcs = OSSTaskCompletionSource<AnyObject>()
let task = client.multipartUpload(request)
task.continue({ (t) -> Any? in
XCTAssertNotNil(t.error)
let error = t.error! as NSError
XCTAssertEqual(OSSClientErrorCODE.codeTaskCancelled.rawValue, error.code)
tcs.setError(error)
return nil
})
// 3秒后取消上传请求
DispatchQueue.global().asyncAfter(deadline: .now() + 3) {
request.cancel()
}
tcs.task.waitUntilFinished()
}