Add tests for errors across isolates

This commit is contained in:
Simon Binder 2020-06-23 19:35:31 +02:00
parent d881659db6
commit b4aeacdba3
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 20 additions and 1 deletions

View File

@ -147,7 +147,7 @@ class IsolateCommunication {
/// Sends an erroneous response for a [Request].
void respondError(Request request, dynamic error, [StackTrace trace]) {
// sending a message while closed with throw, so don't even try.
// sending a message while closed will throw, so don't even try.
if (isClosed) return;
_send(_ErrorResponse(request.id, error.toString(), trace.toString()));

View File

@ -59,6 +59,25 @@ void main() {
await expectation;
await moorIsolate.shutdownAll();
});
test('errors propagate across isolates', () async {
final isolate = await MoorIsolate.spawn(_backgroundConnection);
final db = TodoDb.connect(await isolate.connect());
await expectLater(
() => db.customStatement('UPDATE non_existing_table SET foo = bar'),
throwsA(anything),
);
// Check that isolate is still usable
await expectLater(
db.customSelect('SELECT 1').get(),
completion(isNotEmpty),
);
await db.close();
await isolate.shutdownAll();
});
}
void _runTests(