|
6 | 6 | // Copyright (c) 2014 GitHub. All rights reserved.
|
7 | 7 | //
|
8 | 8 |
|
| 9 | +#if canImport(Darwin) |
| 10 | +import Darwin.sys.qos |
| 11 | +#endif |
9 | 12 | import Dispatch
|
10 | 13 | import Foundation
|
11 | 14 |
|
@@ -261,6 +264,45 @@ class SchedulerSpec: QuickSpec {
|
261 | 264 | // enough time to ensure that the first timer was actually cancelled.
|
262 | 265 | expect(count).toEventually(equal(timesToRun))
|
263 | 266 | }
|
| 267 | + |
| 268 | + it("should propagate QoS values by default") { |
| 269 | + expect(scheduler.queue.qos).to(equal(.unspecified)) |
| 270 | + |
| 271 | + // qos_class_self() may not be available on non-Darwin |
| 272 | + // platforms, and it's unclear if QoS propagation is |
| 273 | + // implemented in an equivalent manner in such contexts, |
| 274 | + // so we restrict runtime validation tests to Darwin. |
| 275 | + #if canImport(Darwin) |
| 276 | + let userInitiatedQueue = DispatchQueue( |
| 277 | + label: "reactiveswift.tests.user-initiated", |
| 278 | + qos: .userInitiated |
| 279 | + ) |
| 280 | + userInitiatedQueue.suspend() |
| 281 | + |
| 282 | + var initialQoS: qos_class_t? |
| 283 | + var endQoS: qos_class_t? |
| 284 | + |
| 285 | + userInitiatedQueue.async { |
| 286 | + initialQoS = qos_class_self() |
| 287 | + |
| 288 | + // scheduling should propagate QoS values by default |
| 289 | + scheduler.schedule { |
| 290 | + endQoS = qos_class_self() |
| 291 | + } |
| 292 | + } |
| 293 | + |
| 294 | + scheduler.queue.resume() |
| 295 | + userInitiatedQueue.resume() |
| 296 | + |
| 297 | + expect(initialQoS).toEventuallyNot(beNil()) |
| 298 | + expect(endQoS).toEventuallyNot(beNil()) |
| 299 | + |
| 300 | + expect(initialQoS).to(equal(QOS_CLASS_USER_INITIATED)) |
| 301 | + expect(endQoS?.rawValue).to(beGreaterThanOrEqualTo( |
| 302 | + initialQoS?.rawValue |
| 303 | + )) |
| 304 | + #endif // canImport(Darwin) |
| 305 | + } |
264 | 306 | }
|
265 | 307 | }
|
266 | 308 |
|
|
0 commit comments