@@ -5,47 +5,6 @@ import Sharing
55import SharingGRDB
66import Testing
77
8- private struct SyncUp : Codable , Equatable , FetchableRecord , MutablePersistableRecord {
9- var id : Int64 ?
10- var isActive : Bool
11- var title : String
12- static let databaseTableName = " syncUps "
13- mutating func didInsert( _ inserted: InsertionSuccess ) {
14- id = inserted. rowID
15- }
16- }
17-
18- private struct Attendee : Codable , Equatable , FetchableRecord , MutablePersistableRecord {
19- var id : Int64 ?
20- var name : String
21- var syncUpID : Int
22- static let databaseTableName = " attendees "
23- mutating func didInsert( _ inserted: InsertionSuccess ) {
24- id = inserted. rowID
25- }
26- }
27-
28- private extension DatabaseWriter where Self == DatabaseQueue {
29- static func syncUps( ) throws -> Self {
30- let database = try DatabaseQueue ( )
31- var migrator = DatabaseMigrator ( )
32- migrator. registerMigration ( " Create schema " ) { db in
33- try db. create ( table: SyncUp . databaseTableName) { t in
34- t. autoIncrementedPrimaryKey ( " id " )
35- t. column ( " isActive " , . boolean) . notNull ( )
36- t. column ( " title " , . text) . notNull ( )
37- }
38- try db. create ( table: Attendee . databaseTableName) { t in
39- t. autoIncrementedPrimaryKey ( " id " )
40- t. column ( " syncUpID " , . integer) . notNull ( )
41- t. column ( " name " , . text) . notNull ( )
42- }
43- }
44- try migrator. migrate ( database)
45- return database
46- }
47- }
48-
498@Suite ( . dependency( \. defaultDatabase, try . syncUps( ) ) )
509struct IntegrationTests {
5110 @Test
@@ -59,19 +18,19 @@ struct IntegrationTests {
5918 _ = try SyncUp ( isActive: true , title: " Engineering " )
6019 . inserted ( db)
6120 }
62- try await Task . sleep ( for : . seconds ( 0.1 ) )
21+ try await Task . sleep ( nanoseconds : 10_000_000 )
6322 #expect( syncUps == [ SyncUp ( id: 1 , isActive: true , title: " Engineering " ) ] )
6423 try await database. write { db in
6524 _ = try SyncUp ( id: 1 , isActive: false , title: " Engineering " )
6625 . saved ( db)
6726 }
68- try await Task . sleep ( for : . seconds ( 0.1 ) )
27+ try await Task . sleep ( nanoseconds : 10_000_000 )
6928 #expect( syncUps == [ ] )
7029 try await database. write { db in
7130 _ = try SyncUp ( id: 1 , isActive: true , title: " Engineering " )
7231 . saved ( db)
7332 }
74- try await Task . sleep ( for : . seconds ( 0.1 ) )
33+ try await Task . sleep ( nanoseconds : 10_000_000 )
7534 #expect( syncUps == [ SyncUp ( id: 1 , isActive: true , title: " Engineering " ) ] )
7635 }
7736
@@ -86,23 +45,64 @@ struct IntegrationTests {
8645 _ = try SyncUp ( isActive: true , title: " Engineering " )
8746 . inserted ( db)
8847 }
89- try await Task . sleep ( for : . seconds ( 0.1 ) )
48+ try await Task . sleep ( nanoseconds : 10_000_000 )
9049 #expect( syncUps == [ SyncUp ( id: 1 , isActive: true , title: " Engineering " ) ] )
9150 try await database. write { db in
9251 _ = try SyncUp ( id: 1 , isActive: false , title: " Engineering " )
9352 . saved ( db)
9453 }
95- try await Task . sleep ( for : . seconds ( 0.1 ) )
54+ try await Task . sleep ( nanoseconds : 10_000_000 )
9655 #expect( syncUps == [ ] )
9756 try await database. write { db in
9857 _ = try SyncUp ( id: 1 , isActive: true , title: " Engineering " )
9958 . saved ( db)
10059 }
101- try await Task . sleep ( for : . seconds ( 0.1 ) )
60+ try await Task . sleep ( nanoseconds : 10_000_000 )
10261 #expect( syncUps == [ SyncUp ( id: 1 , isActive: true , title: " Engineering " ) ] )
10362 }
10463}
10564
65+ private struct SyncUp : Codable , Equatable , FetchableRecord , MutablePersistableRecord {
66+ var id : Int64 ?
67+ var isActive : Bool
68+ var title : String
69+ static let databaseTableName = " syncUps "
70+ mutating func didInsert( _ inserted: InsertionSuccess ) {
71+ id = inserted. rowID
72+ }
73+ }
74+
75+ private struct Attendee : Codable , Equatable , FetchableRecord , MutablePersistableRecord {
76+ var id : Int64 ?
77+ var name : String
78+ var syncUpID : Int
79+ static let databaseTableName = " attendees "
80+ mutating func didInsert( _ inserted: InsertionSuccess ) {
81+ id = inserted. rowID
82+ }
83+ }
84+
85+ private extension DatabaseWriter where Self == DatabaseQueue {
86+ static func syncUps( ) throws -> Self {
87+ let database = try DatabaseQueue ( )
88+ var migrator = DatabaseMigrator ( )
89+ migrator. registerMigration ( " Create schema " ) { db in
90+ try db. create ( table: SyncUp . databaseTableName) { t in
91+ t. autoIncrementedPrimaryKey ( " id " )
92+ t. column ( " isActive " , . boolean) . notNull ( )
93+ t. column ( " title " , . text) . notNull ( )
94+ }
95+ try db. create ( table: Attendee . databaseTableName) { t in
96+ t. autoIncrementedPrimaryKey ( " id " )
97+ t. column ( " syncUpID " , . integer) . notNull ( )
98+ t. column ( " name " , . text) . notNull ( )
99+ }
100+ }
101+ try migrator. migrate ( database)
102+ return database
103+ }
104+ }
105+
106106private struct ActiveSyncUps : FetchKeyRequest {
107107 func fetch( _ db: Database ) throws -> [ SyncUp ] {
108108 try SyncUp
0 commit comments