Skip to content

Commit 0c2949d

Browse files
panvanodejs-github-bot
authored andcommitted
test: move large SQLite string cases to pummel
The oversized-string cases allocate hundreds of megabytes and can make the ordinary statement test time out under parallel suite load. Move all five cases unchanged to the sequential pummel suite, which also allows more time for intensive tests. Refs: nodejs/reliability#1690 Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: #66722 Refs: nodejs/reliability#1686 Refs: nodejs/reliability#1687 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
1 parent c172bcd commit 0c2949d

2 files changed

Lines changed: 61 additions & 54 deletions

File tree

‎test/parallel/test-sqlite-statement.js‎

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// Flags: --expose-gc
22
'use strict';
3-
const { enoughTestMem, skipIfSQLiteMissing } = require('../common');
3+
const { skipIfSQLiteMissing } = require('../common');
44
skipIfSQLiteMissing();
55
const {
66
Database,
77
Statement,
8-
constants: { SQLITE_OK },
98
} = require('node:sqlite');
10-
const { constants } = require('node:buffer');
119
const { suite, test } = require('node:test');
1210

1311
suite('Statement() constructor', () => {
@@ -1447,54 +1445,3 @@ suite('options.persistent', () => {
14471445
t.assert.deepStrictEqual(stmt.get(), { __proto__: null, val: 42n });
14481446
});
14491447
});
1450-
1451-
suite('values larger than the maximum string length', { skip: !enoughTestMem }, () => {
1452-
// hex() doubles its input, so this is the smallest blob whose text form
1453-
// exceeds what V8 can hold in a string.
1454-
const blobSize = (constants.MAX_STRING_LENGTH >>> 1) + 1;
1455-
// '\u20ac' is 1 UTF-16 code unit but 3 UTF-8 bytes, so this identifier is a
1456-
// valid JS string whose UTF-8 form exceeds the limit.
1457-
const longIdentifier = '\u20ac'.repeat(Math.ceil(constants.MAX_STRING_LENGTH / 3) + 10);
1458-
const tooLong = { code: 'ERR_STRING_TOO_LONG', name: 'Error' };
1459-
1460-
test('get() throws instead of returning undefined', (t) => {
1461-
using db = new Database(':memory:');
1462-
using stmt = db.prepare('SELECT hex(zeroblob(?))');
1463-
t.assert.throws(() => {
1464-
stmt.get(blobSize);
1465-
}, tooLong);
1466-
});
1467-
1468-
test('prepare() throws when the SQLite error message is too long', (t) => {
1469-
using db = new Database(':memory:');
1470-
// SQLite repeats the identifier in the error.
1471-
t.assert.throws(() => {
1472-
db.prepare(`SELECT 1 FROM "${longIdentifier}"`);
1473-
}, tooLong);
1474-
});
1475-
1476-
test('prepare() throws for an oversized authorizer argument', (t) => {
1477-
using db = new Database(':memory:');
1478-
db.setAuthorizer(() => SQLITE_OK);
1479-
t.assert.throws(() => db.prepare(`CREATE TABLE "${longIdentifier}" (x)`), tooLong);
1480-
});
1481-
1482-
test('columns() throws for an oversized declared type', (t) => {
1483-
using db = new Database(':memory:');
1484-
db.exec(`CREATE TABLE t (x "${longIdentifier}")`);
1485-
using stmt = db.prepare('SELECT x FROM t');
1486-
t.assert.throws(() => stmt.columns(), tooLong);
1487-
});
1488-
1489-
test('exec() surfaces the error from a user-defined function', (t) => {
1490-
using db = new Database(':memory:');
1491-
db.exec('CREATE TABLE data(val TEXT)');
1492-
db.function('identity', (val) => val);
1493-
1494-
t.assert.throws(() => {
1495-
db.exec(`INSERT INTO data (val) VALUES (identity(hex(zeroblob(${blobSize}))))`);
1496-
}, tooLong);
1497-
using stmt = db.prepare('SELECT count(*) AS count FROM data');
1498-
t.assert.deepStrictEqual(stmt.get(), { __proto__: null, count: 0 });
1499-
});
1500-
});
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict';
2+
3+
const { enoughTestMem, skipIfSQLiteMissing } = require('../common');
4+
skipIfSQLiteMissing();
5+
const { Database, constants: { SQLITE_OK } } = require('node:sqlite');
6+
const { constants } = require('node:buffer');
7+
const { suite, test } = require('node:test');
8+
9+
// These queries allocate strings and blobs of several hundred megabytes.
10+
// Run them separately from the ordinary statement tests.
11+
suite('values larger than the maximum string length', { skip: !enoughTestMem }, () => {
12+
// hex() doubles its input, so this is the smallest blob whose text form
13+
// exceeds what V8 can hold in a string.
14+
const blobSize = (constants.MAX_STRING_LENGTH >>> 1) + 1;
15+
// '\u20ac' is 1 UTF-16 code unit but 3 UTF-8 bytes, so this identifier is a
16+
// valid JS string whose UTF-8 form exceeds the limit.
17+
const longIdentifier = '\u20ac'.repeat(Math.ceil(constants.MAX_STRING_LENGTH / 3) + 10);
18+
const tooLong = { code: 'ERR_STRING_TOO_LONG', name: 'Error' };
19+
20+
test('get() throws instead of returning undefined', (t) => {
21+
using db = new Database(':memory:');
22+
using stmt = db.prepare('SELECT hex(zeroblob(?))');
23+
t.assert.throws(() => {
24+
stmt.get(blobSize);
25+
}, tooLong);
26+
});
27+
28+
test('prepare() throws when the SQLite error message is too long', (t) => {
29+
using db = new Database(':memory:');
30+
// SQLite repeats the identifier in the error.
31+
t.assert.throws(() => {
32+
db.prepare(`SELECT 1 FROM "${longIdentifier}"`);
33+
}, tooLong);
34+
});
35+
36+
test('prepare() throws for an oversized authorizer argument', (t) => {
37+
using db = new Database(':memory:');
38+
db.setAuthorizer(() => SQLITE_OK);
39+
t.assert.throws(() => db.prepare(`CREATE TABLE "${longIdentifier}" (x)`), tooLong);
40+
});
41+
42+
test('columns() throws for an oversized declared type', (t) => {
43+
using db = new Database(':memory:');
44+
db.exec(`CREATE TABLE t (x "${longIdentifier}")`);
45+
using stmt = db.prepare('SELECT x FROM t');
46+
t.assert.throws(() => stmt.columns(), tooLong);
47+
});
48+
49+
test('exec() surfaces the error from a user-defined function', (t) => {
50+
using db = new Database(':memory:');
51+
db.exec('CREATE TABLE data(val TEXT)');
52+
db.function('identity', (val) => val);
53+
54+
t.assert.throws(() => {
55+
db.exec(`INSERT INTO data (val) VALUES (identity(hex(zeroblob(${blobSize}))))`);
56+
}, tooLong);
57+
using stmt = db.prepare('SELECT count(*) AS count FROM data');
58+
t.assert.deepStrictEqual(stmt.get(), { __proto__: null, count: 0 });
59+
});
60+
});

0 commit comments

Comments
 (0)