Add regression test for #1442

This commit is contained in:
Simon Binder 2021-08-31 21:15:54 +02:00
parent b9c609a5f2
commit 580d99ce24
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
1 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,39 @@
@TestOn('vm')
import 'dart:async';
import 'package:test/test.dart';
import 'package:moor/ffi.dart';
import 'package:moor/moor.dart';
class _TestDb extends GeneratedDatabase {
_TestDb() : super(const SqlTypeSystem.withDefaults(), VmDatabase.memory());
@override
final List<TableInfo> allTables = const [];
@override
final int schemaVersion = 1;
}
Future<int> _selectOne(_TestDb _db) =>
_db.customSelect('select 1 a').map((row) => row.read<int>('a')).getSingle();
void main() {
for (final useTransaction in [false, true]) {
test('query after db.close, useTransaction=$useTransaction', () async {
final db = _TestDb();
expect(await _selectOne(db), 1);
await db.close();
expect(
() async {
if (useTransaction) {
await db.transaction(() => _selectOne(db));
} else {
await _selectOne(db);
}
},
throwsA(isA<StateError>().having((e) => e.message, 'message',
contains("Can't re-open a database after closing it."))),
);
});
}
}