Skip to content

Commit 02bb9ce

Browse files
committed
Update existing tests to accommodate dispatching changes
1 parent 9fa6b3c commit 02bb9ce

6 files changed

Lines changed: 36 additions & 33 deletions

File tree

Tests/A+/Swift/0.0.0.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import PromiseKit
1+
@testable import PromiseKit
22
import Dispatch
33
import XCTest
44

@@ -12,7 +12,8 @@ private let timeout: TimeInterval = 10
1212
extension XCTestCase {
1313
func describe(_ description: String, file: StaticString = #file, line: UInt = #line, body: () throws -> Void) {
1414

15-
PromiseKit.conf.Q.map = .main
15+
conf.testMode = true // Allow free setting of default dispatchers
16+
conf.setDefaultDispatchers(body: .main)
1617

1718
do {
1819
try body()

Tests/Cancel/DefaultDispatchQueueTests.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import class Foundation.Thread
2-
import PromiseKit
2+
@testable import PromiseKit
33
import Dispatch
44
import XCTest
55

@@ -10,13 +10,12 @@ class CancellableDefaultDispatchQueueTest: XCTestCase {
1010
let myQueue = DispatchQueue(label: "myQueue")
1111

1212
override func setUp() {
13-
// can actually only set the default queue once
14-
// - See: PMKSetDefaultDispatchQueue
15-
conf.Q = (myQueue, myQueue)
13+
conf.testMode = true // Allow free setting of default dispatchers
14+
conf.setDefaultDispatchers(body: myQueue, tail: myQueue)
1615
}
1716

1817
override func tearDown() {
19-
conf.Q = (.main, .main)
18+
conf.setDefaultDispatchers(body: .main, tail: .main)
2019
}
2120

2221
func testOverrodeDefaultThenQueue() {

Tests/Cancel/DispatcherTests.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Dispatch
2-
import PromiseKit
2+
@testable import PromiseKit
33
import XCTest
44

55
fileprivate let queueIDKey = DispatchSpecificKey<Int>()
@@ -48,8 +48,9 @@ class DispatcherTests: XCTestCase {
4848

4949
let ex = expectation(description: "DispatchQueue compatibility")
5050

51-
let oldConf = PromiseKit.conf.D
52-
PromiseKit.conf.D = (map: dispatcher, return: dispatcher)
51+
let oldConf = conf.D
52+
conf.testMode = true
53+
conf.D = (body: dispatcher, tail: dispatcher)
5354

5455
let background = DispatchQueue.global(qos: .background)
5556
background.setSpecific(key: queueIDKey, value: 100)

Tests/Core/DefaultDispatchQueueTests.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
import class Foundation.Thread
10-
import PromiseKit
10+
@testable import PromiseKit
1111
import Dispatch
1212
import XCTest
1313

@@ -19,13 +19,12 @@ class PMKDefaultDispatchQueueTest: XCTestCase {
1919
let myQueue = DispatchQueue(label: "myQueue")
2020

2121
override func setUp() {
22-
// can actually only set the default queue once
23-
// - See: PMKSetDefaultDispatchQueue
24-
conf.Q = (myQueue, myQueue)
22+
conf.testMode = true // Allow free setting of default dispatchers
23+
conf.setDefaultDispatchers(body: myQueue, tail: myQueue)
2524
}
2625

2726
override func tearDown() {
28-
conf.Q = (.main, .main)
27+
conf.setDefaultDispatchers(body: .main, tail: .main)
2928
}
3029

3130
func testOverrodeDefaultThenQueue() {

Tests/Core/DispatcherTests.swift

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Dispatch
2-
import PromiseKit
2+
@testable import PromiseKit
33
import XCTest
44

55
fileprivate let queueIDKey = DispatchSpecificKey<Int>()
@@ -33,13 +33,14 @@ class DispatcherTests: XCTestCase {
3333
dispatcherB = RecordingDispatcher()
3434
}
3535

36-
func testConfD() {
37-
let ex = expectation(description: "conf.D")
38-
let oldConf = PromiseKit.conf.D
39-
PromiseKit.conf.D.map = dispatcher
40-
PromiseKit.conf.D.return = dispatcherB
41-
XCTAssertNil(PromiseKit.conf.Q.map, "conf.Q.map not nil") // Not representable as DispatchQueues
42-
XCTAssertNil(PromiseKit.conf.Q.return, "conf.Q.return not nil")
36+
func testConfQRepresentation() {
37+
let ex = expectation(description: "Default dispatchers")
38+
let oldConf = conf.D
39+
conf.testMode = true
40+
conf.D.body = dispatcher
41+
conf.D.tail = dispatcherB
42+
XCTAssertNil(conf.Q.map, "conf.Q.map not nil") // Not representable as DispatchQueues
43+
XCTAssertNil(conf.Q.return, "conf.Q.return not nil")
4344
Promise { seal in
4445
seal.fulfill(42)
4546
}.map {
@@ -52,16 +53,16 @@ class DispatcherTests: XCTestCase {
5253
}.cauterize()
5354
waitForExpectations(timeout: 1)
5455
let testQueue = DispatchQueue(label: "test queue")
55-
PromiseKit.conf.D.map = testQueue // Assign DispatchQueue to Dispatcher variable
56-
PromiseKit.conf.Q.return = testQueue // Assign DispatchQueue to DispatchQueue variable
57-
XCTAssert(PromiseKit.conf.Q.map === testQueue, "did not get main DispatchQueue back from map")
58-
XCTAssert((PromiseKit.conf.D.return as? DispatchQueue)! === testQueue, "did not get main DispatchQueue back from return")
59-
PromiseKit.conf.D = oldConf
56+
conf.setDefaultDispatchers(body: testQueue) // Assign DispatchQueue to Dispatcher variable
57+
conf.Q.return = testQueue // Assign DispatchQueue to DispatchQueue variable
58+
XCTAssert(conf.Q.map === testQueue, "did not get main DispatchQueue back from map")
59+
XCTAssert((conf.D.tail as? DispatchQueue)! === testQueue, "did not get main DispatchQueue back from return")
60+
conf.D = oldConf
6061
}
6162

6263
func testPMKDefaultIdentity() {
6364
// If this identity does not hold, the DispatchQueue wrapper API will not behave correctly
64-
XCTAssert(DispatchQueue.pmkDefault === DispatchQueue.pmkDefault, "DispatchQueues are not object-identity-preserving on this platform")
65+
XCTAssert(DispatchQueue.unspecified === DispatchQueue.unspecified, "DispatchQueues are not object-identity-preserving on this platform")
6566
}
6667

6768
func testDispatcherWithThrow() {
@@ -81,8 +82,9 @@ class DispatcherTests: XCTestCase {
8182

8283
let ex = expectation(description: "DispatchQueue compatibility")
8384

84-
let oldConf = PromiseKit.conf.D
85-
PromiseKit.conf.D = (map: dispatcher, return: dispatcher)
85+
let oldConf = conf.D
86+
conf.testMode = true
87+
conf.D = (body: dispatcher, tail: dispatcher)
8688

8789
let background = DispatchQueue.global(qos: .background)
8890
background.setSpecific(key: queueIDKey, value: 100)

Tests/Core/LoggingTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,15 @@ class LoggingTests: XCTestCase {
143143

144144
conf.logHandler = captureLogger
145145
Guarantee.value(42).done(on: nil, flags: .barrier) { _ in }
146-
XCTAssertEqual ("nilDispatchQueueWithFlags", logOutput!)
146+
XCTAssertEqual ("extraneousFlagsSpecified", logOutput!)
147147
}
148148

149149
// Verify extraneousFlagsSpecified is logged
150150
func testExtraneousFlagsSpecified() {
151151

152152
conf.logHandler = captureLogger
153-
conf.D.return = CurrentThreadDispatcher()
153+
conf.testMode = true
154+
conf.D.tail = CurrentThreadDispatcher()
154155
Guarantee.value(42).done(flags: .barrier) { _ in }
155156
XCTAssertEqual ("extraneousFlagsSpecified", logOutput!)
156157
}

0 commit comments

Comments
 (0)