@@ -3,7 +3,6 @@ import Dispatch
33import Foundation
44@testable import GRDB
55
6- #if canImport(Darwin) // needs NSFileCoordinator
76class DatabasePoolConcurrencyTests : GRDBTestCase {
87
98 func testDatabasePoolFundamental1( ) throws {
@@ -880,8 +879,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
880879
881880 // This test CAN break in future releases: the dispatch queue labels
882881 // are documented to be a debug-only tool.
882+ #if canImport(Darwin) // __dispatch_queue_get_label unavailable on non-Darwin platforms
883883 let label = String ( utf8String: __dispatch_queue_get_label ( nil ) )
884884 XCTAssertEqual ( label, " GRDB.DatabasePool.writer " )
885+ #endif
885886 }
886887
887888 let s1 = DispatchSemaphore ( value: 0 )
@@ -893,9 +894,11 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
893894
894895 // This test CAN break in future releases: the dispatch queue labels
895896 // are documented to be a debug-only tool.
897+ #if canImport(Darwin) // __dispatch_queue_get_label unavailable on non-Darwin platforms
896898 let label = String ( utf8String: __dispatch_queue_get_label ( nil ) )
897899 XCTAssertEqual ( label, " GRDB.DatabasePool.reader.1 " )
898-
900+ #endif
901+
899902 _ = s1. signal ( )
900903 _ = s2. wait ( timeout: . distantFuture)
901904 }
@@ -909,8 +912,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
909912
910913 // This test CAN break in future releases: the dispatch queue labels
911914 // are documented to be a debug-only tool.
915+ #if canImport(Darwin) // __dispatch_queue_get_label unavailable on non-Darwin platforms
912916 let label = String ( utf8String: __dispatch_queue_get_label ( nil ) )
913917 XCTAssertEqual ( label, " GRDB.DatabasePool.reader.2 " )
918+ #endif
914919 }
915920 }
916921 let blocks = [ block1, block2]
@@ -928,8 +933,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
928933
929934 // This test CAN break in future releases: the dispatch queue labels
930935 // are documented to be a debug-only tool.
936+ #if canImport(Darwin) // __dispatch_queue_get_label unavailable on non-Darwin platforms
931937 let label = String ( utf8String: __dispatch_queue_get_label ( nil ) )
932938 XCTAssertEqual ( label, " Toreador.writer " )
939+ #endif
933940 }
934941
935942 let s1 = DispatchSemaphore ( value: 0 )
@@ -941,9 +948,11 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
941948
942949 // This test CAN break in future releases: the dispatch queue labels
943950 // are documented to be a debug-only tool.
951+ #if canImport(Darwin) // __dispatch_queue_get_label unavailable on non-Darwin platforms
944952 let label = String ( utf8String: __dispatch_queue_get_label ( nil ) )
945953 XCTAssertEqual ( label, " Toreador.reader.1 " )
946-
954+ #endif
955+
947956 _ = s1. signal ( )
948957 _ = s2. wait ( timeout: . distantFuture)
949958 }
@@ -957,8 +966,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
957966
958967 // This test CAN break in future releases: the dispatch queue labels
959968 // are documented to be a debug-only tool.
969+ #if canImport(Darwin) // __dispatch_queue_get_label unavailable on non-Darwin platforms
960970 let label = String ( utf8String: __dispatch_queue_get_label ( nil ) )
961971 XCTAssertEqual ( label, " Toreador.reader.2 " )
972+ #endif
962973 }
963974 }
964975 let blocks = [ block1, block2]
@@ -1056,6 +1067,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
10561067 // > because DISPATCH_QUEUE_OVERCOMMIT is not a public API. I don't
10571068 // > know of a way to get a reference to the overcommit queue using
10581069 // > only public APIs.
1070+ #if !canImport(Darwin)
1071+ throw XCTSkip ( " __dispatch_get_global_queue unavailable " )
1072+ #else
10591073 let DISPATCH_QUEUE_OVERCOMMIT : UInt = 2
10601074 let targetQueue = __dispatch_get_global_queue (
10611075 Int ( qos. qosClass. rawValue. rawValue) ,
@@ -1069,6 +1083,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
10691083 try dbPool. read { _ in
10701084 dispatchPrecondition ( condition: . onQueue( targetQueue) )
10711085 }
1086+ #endif
10721087 }
10731088
10741089 try test ( qos: . background)
@@ -1255,6 +1270,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
12551270 // MARK: - Concurrent opening
12561271
12571272 func testConcurrentOpening( ) throws {
1273+ #if !canImport(ObjectiveC)
1274+ throw XCTSkip ( " NSFileCoordinator unavailable " )
1275+ #else
12581276 for _ in 0 ..< 50 {
12591277 let dbDirectoryName = " DatabasePoolConcurrencyTests- \( ProcessInfo . processInfo. globallyUniqueString) "
12601278 let directoryURL = URL ( fileURLWithPath: NSTemporaryDirectory ( ) , isDirectory: true )
@@ -1278,13 +1296,17 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
12781296 XCTAssert ( poolError ?? coordinatorError == nil )
12791297 }
12801298 }
1299+ #endif
12811300 }
12821301
12831302 // MARK: - NSFileCoordinator sample code tests
12841303
12851304 // Test for sample code in Documentation.docc/DatabaseSharing.md.
12861305 // This test passes if this method compiles
12871306 private func openSharedDatabase( at databaseURL: URL ) throws -> DatabasePool {
1307+ #if !canImport(ObjectiveC)
1308+ throw XCTSkip ( " NSFileCoordinator unavailable " )
1309+ #else
12881310 let coordinator = NSFileCoordinator ( filePresenter: nil )
12891311 var coordinatorError : NSError ?
12901312 var dbPool : DatabasePool ?
@@ -1300,6 +1322,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
13001322 throw error
13011323 }
13021324 return dbPool!
1325+ #endif
13031326 }
13041327
13051328 // Test for sample code in Documentation.docc/DatabaseSharing.md.
@@ -1314,6 +1337,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
13141337 // Test for sample code in Documentation.docc/DatabaseSharing.md.
13151338 // This test passes if this method compiles
13161339 private func openSharedReadOnlyDatabase( at databaseURL: URL ) throws -> DatabasePool ? {
1340+ #if !canImport(ObjectiveC)
1341+ throw XCTSkip ( " NSFileCoordinator unavailable " )
1342+ #else
13171343 let coordinator = NSFileCoordinator ( filePresenter: nil )
13181344 var coordinatorError : NSError ?
13191345 var dbPool : DatabasePool ?
@@ -1329,6 +1355,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
13291355 throw error
13301356 }
13311357 return dbPool
1358+ #endif
13321359 }
13331360
13341361 // Test for sample code in Documentation.docc/DatabaseSharing.md.
@@ -1349,4 +1376,3 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
13491376 }
13501377 }
13511378}
1352- #endif
0 commit comments