@@ -3,7 +3,6 @@ import Dispatch
3
3
import Foundation
4
4
@testable import GRDB
5
5
6
- #if canImport(Darwin) // needs NSFileCoordinator
7
6
class DatabasePoolConcurrencyTests : GRDBTestCase {
8
7
9
8
func testDatabasePoolFundamental1( ) throws {
@@ -880,8 +879,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
880
879
881
880
// This test CAN break in future releases: the dispatch queue labels
882
881
// are documented to be a debug-only tool.
882
+ #if canImport(Darwin) // __dispatch_queue_get_label unavailable on non-Darwin platforms
883
883
let label = String ( utf8String: __dispatch_queue_get_label ( nil ) )
884
884
XCTAssertEqual ( label, " GRDB.DatabasePool.writer " )
885
+ #endif
885
886
}
886
887
887
888
let s1 = DispatchSemaphore ( value: 0 )
@@ -893,9 +894,11 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
893
894
894
895
// This test CAN break in future releases: the dispatch queue labels
895
896
// are documented to be a debug-only tool.
897
+ #if canImport(Darwin) // __dispatch_queue_get_label unavailable on non-Darwin platforms
896
898
let label = String ( utf8String: __dispatch_queue_get_label ( nil ) )
897
899
XCTAssertEqual ( label, " GRDB.DatabasePool.reader.1 " )
898
-
900
+ #endif
901
+
899
902
_ = s1. signal ( )
900
903
_ = s2. wait ( timeout: . distantFuture)
901
904
}
@@ -909,8 +912,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
909
912
910
913
// This test CAN break in future releases: the dispatch queue labels
911
914
// are documented to be a debug-only tool.
915
+ #if canImport(Darwin) // __dispatch_queue_get_label unavailable on non-Darwin platforms
912
916
let label = String ( utf8String: __dispatch_queue_get_label ( nil ) )
913
917
XCTAssertEqual ( label, " GRDB.DatabasePool.reader.2 " )
918
+ #endif
914
919
}
915
920
}
916
921
let blocks = [ block1, block2]
@@ -928,8 +933,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
928
933
929
934
// This test CAN break in future releases: the dispatch queue labels
930
935
// are documented to be a debug-only tool.
936
+ #if canImport(Darwin) // __dispatch_queue_get_label unavailable on non-Darwin platforms
931
937
let label = String ( utf8String: __dispatch_queue_get_label ( nil ) )
932
938
XCTAssertEqual ( label, " Toreador.writer " )
939
+ #endif
933
940
}
934
941
935
942
let s1 = DispatchSemaphore ( value: 0 )
@@ -941,9 +948,11 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
941
948
942
949
// This test CAN break in future releases: the dispatch queue labels
943
950
// are documented to be a debug-only tool.
951
+ #if canImport(Darwin) // __dispatch_queue_get_label unavailable on non-Darwin platforms
944
952
let label = String ( utf8String: __dispatch_queue_get_label ( nil ) )
945
953
XCTAssertEqual ( label, " Toreador.reader.1 " )
946
-
954
+ #endif
955
+
947
956
_ = s1. signal ( )
948
957
_ = s2. wait ( timeout: . distantFuture)
949
958
}
@@ -957,8 +966,10 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
957
966
958
967
// This test CAN break in future releases: the dispatch queue labels
959
968
// are documented to be a debug-only tool.
969
+ #if canImport(Darwin) // __dispatch_queue_get_label unavailable on non-Darwin platforms
960
970
let label = String ( utf8String: __dispatch_queue_get_label ( nil ) )
961
971
XCTAssertEqual ( label, " Toreador.reader.2 " )
972
+ #endif
962
973
}
963
974
}
964
975
let blocks = [ block1, block2]
@@ -1056,6 +1067,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
1056
1067
// > because DISPATCH_QUEUE_OVERCOMMIT is not a public API. I don't
1057
1068
// > know of a way to get a reference to the overcommit queue using
1058
1069
// > only public APIs.
1070
+ #if !canImport(Darwin)
1071
+ throw XCTSkip ( " __dispatch_get_global_queue unavailable " )
1072
+ #else
1059
1073
let DISPATCH_QUEUE_OVERCOMMIT : UInt = 2
1060
1074
let targetQueue = __dispatch_get_global_queue (
1061
1075
Int ( qos. qosClass. rawValue. rawValue) ,
@@ -1069,6 +1083,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
1069
1083
try dbPool. read { _ in
1070
1084
dispatchPrecondition ( condition: . onQueue( targetQueue) )
1071
1085
}
1086
+ #endif
1072
1087
}
1073
1088
1074
1089
try test ( qos: . background)
@@ -1255,6 +1270,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
1255
1270
// MARK: - Concurrent opening
1256
1271
1257
1272
func testConcurrentOpening( ) throws {
1273
+ #if !canImport(ObjectiveC)
1274
+ throw XCTSkip ( " NSFileCoordinator unavailable " )
1275
+ #else
1258
1276
for _ in 0 ..< 50 {
1259
1277
let dbDirectoryName = " DatabasePoolConcurrencyTests- \( ProcessInfo . processInfo. globallyUniqueString) "
1260
1278
let directoryURL = URL ( fileURLWithPath: NSTemporaryDirectory ( ) , isDirectory: true )
@@ -1278,13 +1296,17 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
1278
1296
XCTAssert ( poolError ?? coordinatorError == nil )
1279
1297
}
1280
1298
}
1299
+ #endif
1281
1300
}
1282
1301
1283
1302
// MARK: - NSFileCoordinator sample code tests
1284
1303
1285
1304
// Test for sample code in Documentation.docc/DatabaseSharing.md.
1286
1305
// This test passes if this method compiles
1287
1306
private func openSharedDatabase( at databaseURL: URL ) throws -> DatabasePool {
1307
+ #if !canImport(ObjectiveC)
1308
+ throw XCTSkip ( " NSFileCoordinator unavailable " )
1309
+ #else
1288
1310
let coordinator = NSFileCoordinator ( filePresenter: nil )
1289
1311
var coordinatorError : NSError ?
1290
1312
var dbPool : DatabasePool ?
@@ -1300,6 +1322,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
1300
1322
throw error
1301
1323
}
1302
1324
return dbPool!
1325
+ #endif
1303
1326
}
1304
1327
1305
1328
// Test for sample code in Documentation.docc/DatabaseSharing.md.
@@ -1314,6 +1337,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
1314
1337
// Test for sample code in Documentation.docc/DatabaseSharing.md.
1315
1338
// This test passes if this method compiles
1316
1339
private func openSharedReadOnlyDatabase( at databaseURL: URL ) throws -> DatabasePool ? {
1340
+ #if !canImport(ObjectiveC)
1341
+ throw XCTSkip ( " NSFileCoordinator unavailable " )
1342
+ #else
1317
1343
let coordinator = NSFileCoordinator ( filePresenter: nil )
1318
1344
var coordinatorError : NSError ?
1319
1345
var dbPool : DatabasePool ?
@@ -1329,6 +1355,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
1329
1355
throw error
1330
1356
}
1331
1357
return dbPool
1358
+ #endif
1332
1359
}
1333
1360
1334
1361
// Test for sample code in Documentation.docc/DatabaseSharing.md.
@@ -1349,4 +1376,3 @@ class DatabasePoolConcurrencyTests: GRDBTestCase {
1349
1376
}
1350
1377
}
1351
1378
}
1352
- #endif
0 commit comments