Skip to content

Commit eb187fe

Browse files
committed
Add test to check for excessive memory usage
Refs #840
1 parent ea8c0d5 commit eb187fe

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"fix": "yarn pretty && eslint --fix .",
5959
"test": "yarn grammar && jest",
6060
"test:watch": "yarn test -- --watch",
61+
"test:perf": "yarn grammar && jest --testMatch '<rootDir>/test/perftest.ts' --coverage=false",
6162
"check": "yarn ts:check && yarn pretty:check && yarn lint && yarn test",
6263
"prepare": "yarn clean && yarn grammar && yarn fix && yarn check && yarn build",
6364
"pre-commit": "npm-run-all --parallel ts:changes lint:changes",

test/perftest.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { format } from '../src/sqlFormatter.js';
2+
3+
const BASELINE = 300;
4+
5+
describe('Performance test', () => {
6+
it('uses about 300 MB of memory to format empty query', () => {
7+
format('', { language: 'sql' });
8+
9+
expect(memoryUsageInMB()).toBeLessThan(BASELINE);
10+
});
11+
12+
// Issue #840
13+
it.skip('should use less than 100 MB of additional memory to format ~100 KB of SQL', () => {
14+
// Long list of values
15+
const values = Array(10000).fill('myid');
16+
const sql = `SELECT ${values.join(', ')}`;
17+
expect(sql.length).toBeGreaterThan(50000);
18+
expect(sql.length).toBeLessThan(100000);
19+
20+
format(sql, { language: 'sql' });
21+
22+
expect(memoryUsageInMB()).toBeLessThan(BASELINE + 100);
23+
});
24+
});
25+
26+
function memoryUsageInMB() {
27+
return Math.round(process.memoryUsage().heapUsed / 1024 / 1024);
28+
}

0 commit comments

Comments
 (0)