Skip to content

[regression]Fix for test_finishTaskAndInvalidate failure #1049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions Foundation/NSURLProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,24 @@ internal class _ProtocolClient : NSObject, URLProtocolClient {
guard let session = task.session as? URLSession else { fatalError() }
switch session.behaviour(for: task) {
case .taskDelegate(let delegate):
guard let s = session as? URLSession else { fatalError() }
s.delegateQueue.addOperation {
delegate.urlSession(s, task: task, didCompleteWithError: nil)
session.delegateQueue.addOperation {
delegate.urlSession(session, task: task, didCompleteWithError: nil)
task.state = .completed
session.taskRegistry.remove(task)
}
case .noDelegate:
task.state = .completed
session.taskRegistry.remove(task)
case .dataCompletionHandler(let completion):
let data = Data()
guard let client = `protocol`.client else { fatalError() }
client.urlProtocol(`protocol`, didLoad: data)
return
case .downloadCompletionHandler(let completion):
guard let s = session as? URLSession else { fatalError() }
s.delegateQueue.addOperation {
session.delegateQueue.addOperation {
completion(task.currentRequest?.url, task.response, nil)
task.state = .completed
session.taskRegistry.remove(task)
}
}
}
Expand All @@ -194,6 +195,7 @@ internal class _ProtocolClient : NSObject, URLProtocolClient {
s.delegateQueue.addOperation {
completion(data, task.response, nil)
task.state = .completed
s.taskRegistry.remove(task)
}
default: return
}
Expand All @@ -204,24 +206,25 @@ internal class _ProtocolClient : NSObject, URLProtocolClient {
guard let session = task.session as? URLSession else { fatalError() }
switch session.behaviour(for: task) {
case .taskDelegate(let delegate):
guard let s = session as? URLSession else { fatalError() }
s.delegateQueue.addOperation {
delegate.urlSession(s, task: task, didCompleteWithError: error as Error)
session.delegateQueue.addOperation {
delegate.urlSession(session, task: task, didCompleteWithError: error as Error)
task.state = .completed
session.taskRegistry.remove(task)
}
case .noDelegate:
task.state = .completed
session.taskRegistry.remove(task)
case .dataCompletionHandler(let completion):
guard let s = session as? URLSession else { fatalError() }
s.delegateQueue.addOperation {
session.delegateQueue.addOperation {
completion(nil, nil, error)
task.state = .completed
session.taskRegistry.remove(task)
}
case .downloadCompletionHandler(let completion):
guard let s = session as? URLSession else { fatalError() }
s.delegateQueue.addOperation {
session.delegateQueue.addOperation {
completion(nil, nil, error)
task.state = .completed
session.taskRegistry.remove(task)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion Foundation/NSURLSession/http/HTTPURLProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ internal class _HTTPURLProtocol: URLProtocol {
self.internalState = .transferFailed
guard let error = self.task?.error else { fatalError() }
completeTask(withError: error)
return
}
}

Expand Down
2 changes: 1 addition & 1 deletion TestFoundation/TestNSURLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestURLSession : XCTestCase {
// ("test_downloadTaskWithURLRequest", test_downloadTaskWithURLRequest),
("test_downloadTaskWithRequestAndHandler", test_downloadTaskWithRequestAndHandler),
("test_downloadTaskWithURLAndHandler", test_downloadTaskWithURLAndHandler),
// ("test_finishTaskAndInvalidate", test_finishTasksAndInvalidate),
("test_finishTaskAndInvalidate", test_finishTasksAndInvalidate),
// ("test_taskError", test_taskError),
("test_taskCopy", test_taskCopy),
// ("test_cancelTask", test_cancelTask),
Expand Down