11import Dispatch
2- import PromiseKit
2+ @ testable import PromiseKit
33import XCTest
44
55fileprivate 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 )
0 commit comments