Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for issue#398 #399

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions test/event_after_closing_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import 'dart:async';

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

import 'docker.dart';

void _print(x) {
// uncomment to debug locally
// print(x);
}

void main() {
withPostgresServer('event after closing', (server) {
Future<void> createTableAndPopulate(Connection conn) async {
final sw = Stopwatch()..start();

await conn.execute('''
CREATE TABLE IF NOT EXISTS large_table (
id SERIAL PRIMARY KEY,
c1 INTEGER NOT NULL,
c2 INTEGER NOT NULL,
c3 TEXT NOT NULL,
c4 TEXT NOT NULL,
c5 TEXT NOT NULL,
c6 TEXT NOT NULL,
c7 TEXT NOT NULL,
c8 TEXT NOT NULL,
c9 TEXT NOT NULL,
c10 TEXT NOT NULL
)
''');

final numBatches = 20;
final batchSize = 5000;

for (var i = 0; i < numBatches; i++) {
_print('Batch $i of $numBatches');
final values = List.generate(
batchSize,
(i) => [
i,
i * 2,
'value $i',
'value $i',
'value $i',
'value $i',
'value $i',
'value $i',
'value $i',
'value $i',
]);

final allArgs = values.expand((e) => e).toList();
final valuesPart = List.generate(
batchSize,
(i) =>
'(${List.generate(10, (j) => '\$${i * 10 + j + 1}').join(', ')})')
.join(', ');

final stmt =
'INSERT INTO large_table (c1, c2, c3, c4, c5, c6, c7, c8, c9, c10) VALUES $valuesPart';
await conn.execute(
stmt,
parameters: allArgs,
);
}

_print('Inserted ${numBatches * batchSize} rows in ${sw.elapsed}');
}

test('issue#398', () async {
final conn = await server.newConnection();
await createTableAndPopulate(conn);

final rows = await conn.execute('SELECT * FROM large_table');
_print('SELECTED ROWS ${rows.length}');

await conn.close();
});
});
}
Loading