Skip to content

Commit 2e57caa

Browse files
bitpshraduh95
authored andcommitted
test: prefer in-memory databases in sqlite tests
Several SQLite tests created temporary file databases through a `nextDb()` helper even though they only exercise SQL behavior and never rely on filesystem persistence. Switch those to `:memory:`, which is faster and drops the temporary-file bookkeeping. Tests that depend on an on-disk or shared database keep using files: the constructor, open() and backup() cases, the timeout and cross-worker suites, and the WAL journal-mode PRAGMA. Refs: #64665 Signed-off-by: Paul Bouchon <mail@bitpshr.net> PR-URL: #64701 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent a06bb51 commit 2e57caa

6 files changed

Lines changed: 54 additions & 98 deletions

‎test/parallel/test-sqlite-data-types.js‎

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
'use strict';
22
const { skipIfSQLiteMissing } = require('../common');
33
skipIfSQLiteMissing();
4-
const tmpdir = require('../common/tmpdir');
5-
const { join } = require('node:path');
64
const { DatabaseSync } = require('node:sqlite');
75
const { suite, test } = require('node:test');
8-
let cnt = 0;
9-
10-
tmpdir.refresh();
11-
12-
function nextDb() {
13-
return join(tmpdir.path, `database-${cnt++}.db`);
14-
}
156

167
suite('data binding and mapping', () => {
178
test('supported data types', (t) => {
189
const u8a = new TextEncoder().encode('a☃b☃c');
19-
const db = new DatabaseSync(nextDb());
10+
const db = new DatabaseSync(':memory:');
2011
t.after(() => { db.close(); });
2112
const setup = db.exec(`
2213
CREATE TABLE types(
@@ -92,7 +83,7 @@ suite('data binding and mapping', () => {
9283
});
9384

9485
test('large strings are bound correctly', (t) => {
95-
const db = new DatabaseSync(nextDb());
86+
const db = new DatabaseSync(':memory:');
9687
t.after(() => { db.close(); });
9788
const setup = db.exec(
9889
'CREATE TABLE data(key INTEGER PRIMARY KEY, text TEXT) STRICT;'
@@ -127,7 +118,7 @@ suite('data binding and mapping', () => {
127118
});
128119

129120
test('unsupported data types', (t) => {
130-
const db = new DatabaseSync(nextDb());
121+
const db = new DatabaseSync(':memory:');
131122
t.after(() => { db.close(); });
132123
const setup = db.exec(
133124
'CREATE TABLE types(key INTEGER PRIMARY KEY, val INTEGER) STRICT;'
@@ -162,7 +153,7 @@ suite('data binding and mapping', () => {
162153

163154
test('throws when binding a BigInt that is too large', (t) => {
164155
const max = 9223372036854775807n; // Largest 64-bit signed integer value.
165-
const db = new DatabaseSync(nextDb());
156+
const db = new DatabaseSync(':memory:');
166157
t.after(() => { db.close(); });
167158
const setup = db.exec(
168159
'CREATE TABLE types(key INTEGER PRIMARY KEY, val INTEGER) STRICT;'
@@ -182,7 +173,7 @@ suite('data binding and mapping', () => {
182173
});
183174

184175
test('statements are unbound on each call', (t) => {
185-
const db = new DatabaseSync(nextDb());
176+
const db = new DatabaseSync(':memory:');
186177
t.after(() => { db.close(); });
187178
const setup = db.exec(
188179
'CREATE TABLE data(key INTEGER PRIMARY KEY, val INTEGER) STRICT;'

‎test/parallel/test-sqlite-named-parameters.js‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
'use strict';
22
const { skipIfSQLiteMissing } = require('../common');
33
skipIfSQLiteMissing();
4-
const tmpdir = require('../common/tmpdir');
5-
const { join } = require('node:path');
64
const { DatabaseSync } = require('node:sqlite');
75
const { suite, test } = require('node:test');
8-
let cnt = 0;
9-
10-
tmpdir.refresh();
11-
12-
function nextDb() {
13-
return join(tmpdir.path, `database-${cnt++}.db`);
14-
}
156

167
suite('named parameters', () => {
178
test('throws on unknown named parameters', (t) => {
18-
const db = new DatabaseSync(nextDb());
9+
const db = new DatabaseSync(':memory:');
1910
t.after(() => { db.close(); });
2011
const setup = db.exec(
2112
'CREATE TABLE types(key INTEGER PRIMARY KEY, val INTEGER) STRICT;'
@@ -32,7 +23,7 @@ suite('named parameters', () => {
3223
});
3324

3425
test('bare named parameters are supported', (t) => {
35-
const db = new DatabaseSync(nextDb());
26+
const db = new DatabaseSync(':memory:');
3627
t.after(() => { db.close(); });
3728
const setup = db.exec(
3829
'CREATE TABLE data(key INTEGER PRIMARY KEY, val INTEGER) STRICT;'
@@ -47,7 +38,7 @@ suite('named parameters', () => {
4738
});
4839

4940
test('duplicate bare named parameters are supported', (t) => {
50-
const db = new DatabaseSync(nextDb());
41+
const db = new DatabaseSync(':memory:');
5142
t.after(() => { db.close(); });
5243
const setup = db.exec(
5344
'CREATE TABLE data(key INTEGER PRIMARY KEY, val INTEGER) STRICT;'
@@ -62,7 +53,7 @@ suite('named parameters', () => {
6253
});
6354

6455
test('bare named parameters throw on ambiguous names', (t) => {
65-
const db = new DatabaseSync(nextDb());
56+
const db = new DatabaseSync(':memory:');
6657
t.after(() => { db.close(); });
6758
const setup = db.exec(
6859
'CREATE TABLE types(key INTEGER PRIMARY KEY, val INTEGER) STRICT;'

0 commit comments

Comments
 (0)