Skip to content

Commit 8d57261

Browse files
authored
Test for issue#398 (#399)
1 parent d3f0a16 commit 8d57261

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

test/event_after_closing_test.dart

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import 'dart:async';
2+
3+
import 'package:postgres/postgres.dart';
4+
import 'package:test/test.dart';
5+
6+
import 'docker.dart';
7+
8+
void _print(x) {
9+
// uncomment to debug locally
10+
// print(x);
11+
}
12+
13+
void main() {
14+
withPostgresServer('event after closing', (server) {
15+
Future<void> createTableAndPopulate(Connection conn) async {
16+
final sw = Stopwatch()..start();
17+
18+
await conn.execute('''
19+
CREATE TABLE IF NOT EXISTS large_table (
20+
id SERIAL PRIMARY KEY,
21+
c1 INTEGER NOT NULL,
22+
c2 INTEGER NOT NULL,
23+
c3 TEXT NOT NULL,
24+
c4 TEXT NOT NULL,
25+
c5 TEXT NOT NULL,
26+
c6 TEXT NOT NULL,
27+
c7 TEXT NOT NULL,
28+
c8 TEXT NOT NULL,
29+
c9 TEXT NOT NULL,
30+
c10 TEXT NOT NULL
31+
)
32+
''');
33+
34+
final numBatches = 20;
35+
final batchSize = 5000;
36+
37+
for (var i = 0; i < numBatches; i++) {
38+
_print('Batch $i of $numBatches');
39+
final values = List.generate(
40+
batchSize,
41+
(i) => [
42+
i,
43+
i * 2,
44+
'value $i',
45+
'value $i',
46+
'value $i',
47+
'value $i',
48+
'value $i',
49+
'value $i',
50+
'value $i',
51+
'value $i',
52+
]);
53+
54+
final allArgs = values.expand((e) => e).toList();
55+
final valuesPart = List.generate(
56+
batchSize,
57+
(i) =>
58+
'(${List.generate(10, (j) => '\$${i * 10 + j + 1}').join(', ')})')
59+
.join(', ');
60+
61+
final stmt =
62+
'INSERT INTO large_table (c1, c2, c3, c4, c5, c6, c7, c8, c9, c10) VALUES $valuesPart';
63+
await conn.execute(
64+
stmt,
65+
parameters: allArgs,
66+
);
67+
}
68+
69+
_print('Inserted ${numBatches * batchSize} rows in ${sw.elapsed}');
70+
}
71+
72+
test('issue#398', () async {
73+
final conn = await server.newConnection();
74+
await createTableAndPopulate(conn);
75+
76+
final rows = await conn.execute('SELECT * FROM large_table');
77+
_print('SELECTED ROWS ${rows.length}');
78+
79+
await conn.close();
80+
});
81+
});
82+
}

0 commit comments

Comments
 (0)