Update for Xcode 11.4 release (#150)

This commit is contained in:
Sergej Jaskiewicz
2020-03-28 21:23:57 +03:00
committed by GitHub
parent 621f970998
commit 30b5dd4c2f
4 changed files with 23 additions and 23 deletions
@@ -40,23 +40,21 @@ internal final class SubjectSubscriber<Downstream: Subject>
internal func receive(_ input: Downstream.Output) -> Subscribers.Demand {
lock.lock()
guard let downstreamSubject = downstreamSubject else {
guard let subject = downstreamSubject, upstreamSubscription != nil else {
lock.unlock()
return .none
}
guard upstreamSubscription != nil else { APIViolationValueBeforeSubscription() }
lock.unlock()
downstreamSubject.send(input)
subject.send(input)
return .none
}
internal func receive(completion: Subscribers.Completion<Downstream.Failure>) {
lock.lock()
guard let subject = downstreamSubject else {
guard let subject = downstreamSubject, upstreamSubscription != nil else {
lock.unlock()
return
}
guard upstreamSubscription != nil else { APIViolationUnexpectedCompletion() }
lock.unlock()
subject.send(completion: completion)
downstreamSubject = nil
@@ -87,11 +85,7 @@ internal final class SubjectSubscriber<Downstream: Subject>
internal func cancel() {
lock.lock()
if isCancelled {
lock.unlock()
return
}
guard let subscription = upstreamSubscription else {
guard !isCancelled, let subscription = upstreamSubscription else {
lock.unlock()
return
}
@@ -78,9 +78,8 @@ extension Publishers.FlatMap {
/// acquired.
private var outerSubscription: Subscription?
// Must be recursive lock. Probably a bug in Combine.
/// The lock for requesting from `outerSubscription`.
private let outerLock = UnfairLock.allocate()
private let outerLock = UnfairRecursiveLock.allocate()
/// The lock for modifying the state. All mutable state here should be
/// read and modified with this lock acquired.
@@ -447,10 +447,7 @@ final class FlatMapTests: XCTestCase {
let childSubscription = CustomSubscription()
let child = CustomPublisher(subscription: childSubscription)
// If Apple changes the implementation to use recursive lock,
// we must make sure no stack overflow occurs here,
// which will also be detected as a crash, which is not what we want.
var recursionDepth = 10
var recursionDepth = 5
helper.subscription.onRequest = { _ in
if recursionDepth <= 0 {
return
@@ -461,9 +458,17 @@ final class FlatMapTests: XCTestCase {
XCTAssertEqual(helper.publisher.send(child), .none)
assertCrashes {
child.send(completion: .finished)
}
child.send(completion: .finished)
XCTAssertEqual(helper.tracking.history, [.subscription("FlatMap")])
XCTAssertEqual(helper.subscription.history, [.requested(.max(1)),
.requested(.max(1)),
.requested(.max(1)),
.requested(.max(1)),
.requested(.max(1)),
.requested(.max(1)),
.requested(.max(1))])
XCTAssertEqual(childSubscription.history, [.requested(.max(1))])
}
func testDownstreamLockReentrance() throws {
@@ -134,15 +134,17 @@ final class ShareTests: XCTestCase {
}
func testShareReceiveValueBeforeSubscription() {
testReceiveValueBeforeSubscription(value: 0,
expected: .crash,
{ $0.share() })
testReceiveValueBeforeSubscription(
value: 0,
expected: .history([.subscription("Multicast")], demand: .none),
{ $0.share() }
)
}
func testShareCompletionBeforeSubscription() {
testReceiveCompletionBeforeSubscription(
inputType: Int.self,
expected: .crash,
expected: .history([.subscription("Multicast")]),
{ $0.share() }
)
}