未验证 提交 736fe64b 编写于 作者: J Jon Shier 提交者: GitHub

Fix Reachability behavior regression from 4.8.1. (#2931)

* Fix regression in reachability behavior.

* Update Example app to recommended localization.

* Update Travis to 10.2.

* Try to enable Travis for hotfix branch.

* Cleanup whitespace.

* Update settings for Example app scheme.

* Fix memory leak in validate().

* Fix memory leak for downloads too.

* Try to fix sim issues by updating to Xcode 10.3 Travis image.

* Another Travis fix.
上级 cc4fdf0b
......@@ -3,6 +3,7 @@ osx_image: xcode10.1
branches:
only:
- master
- hotfix
cache: bundler
env:
global:
......
......@@ -216,10 +216,11 @@
};
buildConfigurationList = F8111E0019A951050040E7D1 /* Build configuration list for PBXProject "iOS Example" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
Base,
en,
);
mainGroup = F8111DFC19A951050040E7D1;
productRefGroup = F8111E0619A951050040E7D1 /* Products */;
......
......@@ -61,14 +61,17 @@
ReferencedContainer = "container:iOS Example.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "OS_ACTIVITY_MODE"
value = "disable"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
<AdditionalOption
key = "MallocStackLogging"
value = ""
isEnabled = "YES">
</AdditionalOption>
<AdditionalOption
key = "PrefersMallocStackLoggingLite"
value = ""
isEnabled = "YES">
</AdditionalOption>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
......
......@@ -159,7 +159,10 @@ open class NetworkReachabilityManager {
let queueEnabled = SCNetworkReachabilitySetDispatchQueue(reachability, listenerQueue)
listenerQueue.async {
self.previousFlags = SCNetworkReachabilityFlags(rawValue: 1 << 30)
guard let flags = self.flags else { return }
self.notifyListener(flags)
}
......
......@@ -500,7 +500,7 @@ open class DownloadRequest: Request {
override open func cancel() {
cancel(createResumeData: true)
}
/// Cancels the request.
///
/// - parameter createResumeData: Determines whether resume data is created via the underlying download task or not.
......
......@@ -219,7 +219,10 @@ extension DataRequest {
/// - returns: The request.
@discardableResult
public func validate() -> Self {
return validate(statusCode: self.acceptableStatusCodes).validate(contentType: self.acceptableContentTypes)
let contentTypes = { [unowned self] in
self.acceptableContentTypes
}
return validate(statusCode: acceptableStatusCodes).validate(contentType: contentTypes())
}
}
......@@ -310,6 +313,9 @@ extension DownloadRequest {
/// - returns: The request.
@discardableResult
public func validate() -> Self {
return validate(statusCode: self.acceptableStatusCodes).validate(contentType: self.acceptableContentTypes)
let contentTypes = { [unowned self] in
self.acceptableContentTypes
}
return validate(statusCode: acceptableStatusCodes).validate(contentType: contentTypes())
}
}
......@@ -27,7 +27,7 @@ import Foundation
import XCTest
class BaseTestCase: XCTestCase {
let timeout: TimeInterval = 30.0
let timeout: TimeInterval = 5.0
static var testDirectoryURL: URL { return FileManager.temporaryDirectoryURL.appendingPathComponent("org.alamofire.tests") }
var testDirectoryURL: URL { return BaseTestCase.testDirectoryURL }
......
......@@ -515,19 +515,19 @@ class DownloadResumeDataTestCase: BaseTestCase {
progressValues.forEach { XCTAssertGreaterThanOrEqual($0, 0.4) }
}
func testThatDownloadCanBeCancelledWithoutResumeData() {
// Given
let expectation = self.expectation(description: "Download should be cancelled")
var cancelled = false
var response: DefaultDownloadResponse?
// When
let download = Alamofire.download(urlString)
download.downloadProgress { progress in
guard !cancelled else { return }
if progress.fractionCompleted > 0.1 {
download.cancel(createResumeData: false)
cancelled = true
......@@ -537,15 +537,15 @@ class DownloadResumeDataTestCase: BaseTestCase {
response = resp
expectation.fulfill()
}
waitForExpectations(timeout: timeout, handler: nil)
// Then
XCTAssertNotNil(response?.request)
XCTAssertNotNil(response?.response)
XCTAssertNil(response?.destinationURL)
XCTAssertNotNil(response?.error)
XCTAssertNil(response?.resumeData)
XCTAssertNil(download.resumeData)
}
......
......@@ -148,6 +148,32 @@ class NetworkReachabilityManagerTestCase: BaseTestCase {
XCTAssertEqual(networkReachabilityStatus, .reachable(.ethernetOrWiFi))
}
func testThatZeroManagerIsNotifiedWhenStoppedAndStarted() {
// Given
let manager = NetworkReachabilityManager()
let first = expectation(description: "first listener notified")
let second = expectation(description: "second listener notified")
// When
manager?.listener = { _ in
first.fulfill()
}
manager?.startListening()
wait(for: [first], timeout: timeout)
manager?.stopListening()
manager?.listener = { _ in
second.fulfill()
}
manager?.startListening()
wait(for: [second], timeout: timeout)
// Then
XCTAssertEqual(manager?.networkReachabilityStatus, .reachable(.ethernetOrWiFi))
}
// MARK: - Tests - Network Reachability Status
func testThatManagerReturnsNotReachableStatusWhenReachableFlagIsAbsent() {
......
......@@ -251,7 +251,7 @@ class SessionManagerTestCase: BaseTestCase {
return "Alamofire/\(build)"
}()
XCTAssertTrue(userAgent?.contains(alamofireVersion) == true)
XCTAssertTrue(userAgent?.contains(osNameVersion) == true)
XCTAssertTrue(userAgent?.contains("Unknown/Unknown") == true)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册