File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -255,4 +255,57 @@ final class GRDBTests: XCTestCase {
255255 await fulfillment ( of: [ expectation] , timeout: 5 )
256256 watchTask. cancel ( )
257257 }
258+
259+ func testGRDBUpdatesFromGRDB( ) async throws {
260+ let expectation = XCTestExpectation ( description: " Watch changes " )
261+
262+ // Create an actor to handle concurrent mutations
263+ actor ResultsStore {
264+ private var results : Set < String > = [ ]
265+
266+ func append( _ names: [ String ] ) {
267+ results. formUnion ( names)
268+ }
269+
270+ func getResults( ) -> Set < String > {
271+ results
272+ }
273+
274+ func count( ) -> Int {
275+ results. count
276+ }
277+ }
278+
279+ let resultsStore = ResultsStore ( )
280+
281+ let watchTask = Task {
282+ let observation = ValueObservation . tracking {
283+ try User . order ( User . Columns. name. asc) . fetchAll ( $0)
284+ }
285+
286+ for try await users in observation. values ( in: pool) {
287+ await resultsStore. append ( users. map { $0. name } )
288+ if await resultsStore. count ( ) == 2 {
289+ expectation. fulfill ( )
290+ }
291+ }
292+ }
293+
294+ try await pool. write { database in
295+ try User (
296+ id: UUID ( ) . uuidString,
297+ name: " one " ,
298+ ) . insert ( database)
299+ }
300+
301+ try await pool. write { database in
302+ try User (
303+ id: UUID ( ) . uuidString,
304+ name: " two " ,
305+ ) . insert ( database)
306+ }
307+
308+ await fulfillment ( of: [ expectation] , timeout: 5 )
309+ watchTask. cancel ( )
310+ }
258311}
You can’t perform that action at this time.
0 commit comments