File tree 1 file changed +41
-0
lines changed
packages/sqlite_async/test
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -253,5 +253,46 @@ void main() {
253
253
done = true ;
254
254
}
255
255
});
256
+
257
+ test ('watch with transaction' , () async {
258
+ final db = await testUtils.setupDatabase (path: path);
259
+ await createTables (db);
260
+
261
+ const baseTime = 20 ;
262
+
263
+ const throttleDuration = Duration (milliseconds: baseTime);
264
+ // delay must be bigger than throttleDuration, and bigger
265
+ // than any internal throttles.
266
+ const delay = Duration (milliseconds: baseTime * 3 );
267
+
268
+ final stream = db.watch ('SELECT count() AS count FROM assets' ,
269
+ throttle: throttleDuration);
270
+
271
+ List <int > counts = [];
272
+
273
+ final subscription = stream.listen ((e) {
274
+ counts.add (e.first['count' ]);
275
+ });
276
+ await Future .delayed (delay);
277
+
278
+ await db.writeTransaction ((tx) async {
279
+ await tx.execute ('INSERT INTO assets(make) VALUES (?)' , ['test1' ]);
280
+ await Future .delayed (delay);
281
+ await tx.execute ('INSERT INTO assets(make) VALUES (?)' , ['test2' ]);
282
+ await Future .delayed (delay);
283
+ });
284
+ await Future .delayed (delay);
285
+
286
+ subscription.cancel ();
287
+
288
+ expect (
289
+ counts,
290
+ equals ([
291
+ // one event when starting the subscription
292
+ 0 ,
293
+ // one event after the transaction
294
+ 2
295
+ ]));
296
+ });
256
297
});
257
298
}
You can’t perform that action at this time.
0 commit comments