Skip to content

Commit e738b8c

Browse files
committed
chore(tests): sync node
1 parent 34fc9cf commit e738b8c

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

scripts/sync-node-tests.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ const skipTests: Record<string, Array<{ name: string; reason: string }>> = {
5959
reason: "Worker thread changeset serialization issue",
6060
},
6161
],
62+
"test-sqlite-template-tag.js": [
63+
{
64+
name: "a tag store keeps the database alive by itself",
65+
reason: "Requires --expose-gc flag",
66+
},
67+
{
68+
name: "tag store prevents circular reference leaks",
69+
reason:
70+
"Requires --expose-gc flag and Node.js internal GC test utilities",
71+
},
72+
],
6273
};
6374

6475
/**

test/node-compat/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ node --test test/node-compat/test-sqlite-statement-sync-columns.test.js
1818
```
1919

2020
Source: https://github.com/nodejs/node/tree/main/test/parallel
21-
Commit: 6beb65e00ef197fdfc392f79e7836bc1761bfd3d
21+
Commit: 6c44d31e2522021b724096939bc44defa42ec6a5

test/node-compat/test-sqlite-template-tag.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010

1111
"use strict";
12+
// Flags: --expose-gc
13+
1214
const assert = require("assert");
1315
const { DatabaseSync } = require("@photostructure/sqlite");
1416
const { test, beforeEach } = require("node:test");
@@ -193,3 +195,39 @@ test("sql error messages are descriptive", () => {
193195
},
194196
);
195197
});
198+
199+
test.skip("a tag store keeps the database alive by itself" /* Requires --expose-gc flag */, () => {
200+
const sql = new DatabaseSync(":memory:").createTagStore();
201+
202+
sql.db.exec("CREATE TABLE test (data INTEGER)");
203+
204+
global.gc();
205+
206+
// eslint-disable-next-line no-unused-expressions
207+
sql.run`INSERT INTO test (data) VALUES (1)`;
208+
});
209+
210+
test.skip("tag store prevents circular reference leaks" /* Requires --expose-gc flag and Node.js internal GC test utilities */, async () => {
211+
const { gcUntil } = require("../common/gc");
212+
213+
const before = process.memoryUsage().heapUsed;
214+
215+
// Create many SQLTagStore + DatabaseSync pairs with circular references
216+
for (let i = 0; i < 1000; i++) {
217+
const sql = new DatabaseSync(":memory:").createTagStore();
218+
sql.db.exec("CREATE TABLE test (data INTEGER)");
219+
// eslint-disable-next-line no-void
220+
sql.db.setAuthorizer(() => void sql.db);
221+
}
222+
223+
// GC until memory stabilizes or give up after 20 attempts
224+
await gcUntil(
225+
"tag store leak check",
226+
() => {
227+
const after = process.memoryUsage().heapUsed;
228+
// Memory should not grow significantly (allow 50% margin for noise)
229+
return after < before * 1.5;
230+
},
231+
20,
232+
);
233+
});

0 commit comments

Comments
 (0)