Skip to content

Commit

Permalink
Updated tests for force-close (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Dec 21, 2024
1 parent a7fba1d commit a37db98
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions test/v3_close_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:postgres/postgres.dart';
import 'package:test/test.dart';

Expand Down Expand Up @@ -92,36 +94,54 @@ void main() {
}

withPostgresServer('connection session', (server) {
test('', () async {
test('connection session', () async {
final conn = await openConnection(server);
// ignore: unawaited_futures
runLongQuery(conn);
final rs = runLongQuery(conn);
// let it start
await Future.delayed(const Duration(milliseconds: 100));
await expectConn1ClosesForcefully(conn);

// TODO: this should be throwing PgException
await expectLater(() => rs, isNotNull);
});
});

withPostgresServer('tx session', (server) {
test('', () async {
test('tx', () async {
final conn = await openConnection(server);
// ignore: unawaited_futures
// Ignore async error, it will fail when the connection is closed and it tries to do COMMIT
conn.runTx(runLongQuery).ignore();
final started = Completer();
final rs = conn.runTx((tx) async {
started.complete();
await runLongQuery(tx);
})
// Ignore async error, it will fail when the connection is closed and it tries to do COMMIT
// TODO: remove this ignore
.ignore();
// let it start
await started.future;
await Future.delayed(const Duration(milliseconds: 100));
await expectConn1ClosesForcefully(conn);

// TODO: this should be throwing PgException
await expectLater(() => rs, isNotNull);
});
});

withPostgresServer('run session', (server) {
test('', () async {
test('run', () async {
final conn = await openConnection(server);
// ignore: unawaited_futures
conn.run(runLongQuery);
final started = Completer();
final rs = conn.run((s) async {
started.complete();
await runLongQuery(s);
});
// let it start
await started.future;
await Future.delayed(const Duration(milliseconds: 100));
await expectConn1ClosesForcefully(conn);

// TODO: this should be throwing PgException
await expectLater(() => rs, isNotNull);
});
});
});
Expand Down

0 comments on commit a37db98

Please sign in to comment.