Skip to content

Commit a37db98

Browse files
authored
Updated tests for force-close (#402)
1 parent a7fba1d commit a37db98

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

test/v3_close_test.dart

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:postgres/postgres.dart';
24
import 'package:test/test.dart';
35

@@ -92,36 +94,54 @@ void main() {
9294
}
9395

9496
withPostgresServer('connection session', (server) {
95-
test('', () async {
97+
test('connection session', () async {
9698
final conn = await openConnection(server);
97-
// ignore: unawaited_futures
98-
runLongQuery(conn);
99+
final rs = runLongQuery(conn);
99100
// let it start
100101
await Future.delayed(const Duration(milliseconds: 100));
101102
await expectConn1ClosesForcefully(conn);
103+
104+
// TODO: this should be throwing PgException
105+
await expectLater(() => rs, isNotNull);
102106
});
103107
});
104108

105109
withPostgresServer('tx session', (server) {
106-
test('', () async {
110+
test('tx', () async {
107111
final conn = await openConnection(server);
108-
// ignore: unawaited_futures
109-
// Ignore async error, it will fail when the connection is closed and it tries to do COMMIT
110-
conn.runTx(runLongQuery).ignore();
112+
final started = Completer();
113+
final rs = conn.runTx((tx) async {
114+
started.complete();
115+
await runLongQuery(tx);
116+
})
117+
// Ignore async error, it will fail when the connection is closed and it tries to do COMMIT
118+
// TODO: remove this ignore
119+
.ignore();
111120
// let it start
121+
await started.future;
112122
await Future.delayed(const Duration(milliseconds: 100));
113123
await expectConn1ClosesForcefully(conn);
124+
125+
// TODO: this should be throwing PgException
126+
await expectLater(() => rs, isNotNull);
114127
});
115128
});
116129

117130
withPostgresServer('run session', (server) {
118-
test('', () async {
131+
test('run', () async {
119132
final conn = await openConnection(server);
120-
// ignore: unawaited_futures
121-
conn.run(runLongQuery);
133+
final started = Completer();
134+
final rs = conn.run((s) async {
135+
started.complete();
136+
await runLongQuery(s);
137+
});
122138
// let it start
139+
await started.future;
123140
await Future.delayed(const Duration(milliseconds: 100));
124141
await expectConn1ClosesForcefully(conn);
142+
143+
// TODO: this should be throwing PgException
144+
await expectLater(() => rs, isNotNull);
125145
});
126146
});
127147
});

0 commit comments

Comments
 (0)