Skip to content

Commit

Permalink
Use unspecified QoS in QueueScheduler when QoS is unspecified
Browse files Browse the repository at this point in the history
  • Loading branch information
jamieQ committed Mar 19, 2024
1 parent 196bf28 commit 46f953c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# master
*Please add new entries at the top.*

1. Change `QueueScheduler` to use unspecified QoS when QoS parameter is defaulted
1. Add support for VisionOS (#875, kudos to @NachoSoto)
1. Fix minimum deployment target of iOS 11 in CocoaPods
1. Fix CI release git tag push trigger (#869, kudos to @p4checo)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Scheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public final class QueueScheduler: DateScheduler {
/// - targeting: (Optional) The queue on which this scheduler's work is
/// targeted
public convenience init(
qos: DispatchQoS = .default,
qos: DispatchQoS = .unspecified,
name: String = "org.reactivecocoa.ReactiveSwift.QueueScheduler",
targeting targetQueue: DispatchQueue? = nil
) {
Expand Down
42 changes: 42 additions & 0 deletions Tests/ReactiveSwiftTests/SchedulerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// Copyright (c) 2014 GitHub. All rights reserved.
//

#if canImport(Darwin)
import Darwin.sys.qos
#endif
import Dispatch
import Foundation

Expand Down Expand Up @@ -261,6 +264,45 @@ class SchedulerSpec: QuickSpec {
// enough time to ensure that the first timer was actually cancelled.
expect(count).toEventually(equal(timesToRun))
}

it("should propagate QoS values by default") {
expect(scheduler.queue.qos).to(equal(.unspecified))

// qos_class_self() may not be available on non-Darwin
// platforms, and it's unclear if QoS propagation is
// implemented in an equivalent manner in such contexts,
// so we restrict runtime validation tests to Darwin.
#if canImport(Darwin)
let userInitiatedQueue = DispatchQueue(
label: "reactiveswift.tests.user-initiated",
qos: .userInitiated
)
userInitiatedQueue.suspend()

var initialQoS: qos_class_t?
var endQoS: qos_class_t?

userInitiatedQueue.async {
initialQoS = qos_class_self()

// scheduling should propagate QoS values by default
scheduler.schedule {
endQoS = qos_class_self()
}
}

scheduler.queue.resume()
userInitiatedQueue.resume()

expect(initialQoS).toEventuallyNot(beNil())
expect(endQoS).toEventuallyNot(beNil())

expect(initialQoS).to(equal(QOS_CLASS_USER_INITIATED))
expect(endQoS?.rawValue).to(beGreaterThanOrEqualTo(
initialQoS?.rawValue
))
#endif // canImport(Darwin)
}
}
}

Expand Down

0 comments on commit 46f953c

Please sign in to comment.