From c71d84ffe6f29cdcf7bf2772d221f9cf14d59106 Mon Sep 17 00:00:00 2001 From: Jamie <2119834+jamieQ@users.noreply.github.com> Date: Sun, 22 Oct 2023 12:50:02 -0500 Subject: [PATCH] Use unspecified QoS in QueueScheduler when QoS is unspecified --- Sources/Scheduler.swift | 2 +- Tests/ReactiveSwiftTests/SchedulerSpec.swift | 33 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Sources/Scheduler.swift b/Sources/Scheduler.swift index 44e6ff549..09101a909 100644 --- a/Sources/Scheduler.swift +++ b/Sources/Scheduler.swift @@ -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 ) { diff --git a/Tests/ReactiveSwiftTests/SchedulerSpec.swift b/Tests/ReactiveSwiftTests/SchedulerSpec.swift index 2e704f125..6171d49ef 100644 --- a/Tests/ReactiveSwiftTests/SchedulerSpec.swift +++ b/Tests/ReactiveSwiftTests/SchedulerSpec.swift @@ -261,6 +261,39 @@ 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)) + + 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 + )) + } } }