Skip to content

Commit d0e493c

Browse files
committed
Add tets
1 parent 58af17e commit d0e493c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

packages/sqlite_async/test/native/watch_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'dart:async';
55
import 'dart:isolate';
66
import 'dart:math';
77

8+
import 'package:async/async.dart';
89
import 'package:sqlite3/common.dart';
910
import 'package:sqlite_async/native.dart';
1011
import 'package:sqlite_async/sqlite_async.dart';
@@ -25,6 +26,16 @@ void main() {
2526
await testUtils.cleanDb(path: path);
2627
});
2728

29+
test('emits updates if stream is listened to before pool is opened',
30+
() async {
31+
final db = await testUtils.setupDatabase();
32+
final updates = StreamQueue(db.updates);
33+
34+
await db.execute('CREATE TABLE a (bar INTEGER);');
35+
await db.execute('INSERT INTO a DEFAULT VALUES');
36+
await expectLater(updates, emits(UpdateNotification({'a'})));
37+
});
38+
2839
test('raw update notifications', () async {
2940
final factory =
3041
(await testUtils.testFactory(path: path)) as NativeSqliteOpenFactory;

packages/sqlite_async/test/watch_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ void main() {
3131
await testUtils.cleanDb(path: path);
3232
});
3333

34+
test('is broadcast stream', () async {
35+
final db = await testUtils.setupDatabase(path: path);
36+
await createTables(db);
37+
38+
expect(db.updates.isBroadcast, isTrue);
39+
var events = 0;
40+
41+
db.updates.listen((_) => events++);
42+
db.updates.listen((_) => events++);
43+
await db.execute('INSERT INTO assets DEFAULT VALUES');
44+
expect(events, 2);
45+
});
46+
3447
test('watch', () async {
3548
final db = await testUtils.setupDatabase(path: path);
3649
await createTables(db);

0 commit comments

Comments
 (0)