Skip to content

Commit 6971baa

Browse files
committed
Add failing test.
1 parent 9c23ce6 commit 6971baa

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

packages/sqlite_async/test/watch_test.dart

+41
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,46 @@ void main() {
253253
done = true;
254254
}
255255
});
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+
});
256297
});
257298
}

0 commit comments

Comments
 (0)