Skip to content

Commit 2a90bb9

Browse files
committed
test: split report OOM tests
On some machines the report OOM tests can take too long to complete, resulting in a timeout. This splits the test into several different smaller tests to reduce the flakiness of it. PR-URL: nodejs#44389 Refs: nodejs/reliability#356 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent fa152f7 commit 2a90bb9

7 files changed

+187
-123
lines changed

test/fixtures/report-oom.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
const list = [];
4+
while (true) {
5+
const record = new MyRecord();
6+
list.push(record);
7+
}
8+
9+
function MyRecord() {
10+
this.name = 'foo';
11+
this.id = 128;
12+
this.account = 98454324;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
// Testcases for situations involving fatal errors, like Javascript heap OOM
4+
5+
require('../common');
6+
const assert = require('assert');
7+
const fs = require('fs');
8+
const helper = require('../common/report.js');
9+
const spawnSync = require('child_process').spawnSync;
10+
const tmpdir = require('../common/tmpdir');
11+
const fixtures = require('../common/fixtures');
12+
13+
// Common args that will cause an out-of-memory error for child process.
14+
const ARGS = [
15+
'--max-old-space-size=20',
16+
fixtures.path('report-oom'),
17+
];
18+
19+
{
20+
// Verify that --report-compact is respected when set.
21+
tmpdir.refresh();
22+
const args = ['--report-on-fatalerror', '--report-compact', ...ARGS];
23+
const child = spawnSync(process.execPath, args, { cwd: tmpdir.path });
24+
assert.notStrictEqual(child.status, 0, 'Process exited unexpectedly');
25+
26+
const reports = helper.findReports(child.pid, tmpdir.path);
27+
assert.strictEqual(reports.length, 1);
28+
29+
const report = reports[0];
30+
helper.validate(report);
31+
assert.strictEqual(require(report).header.threadId, null);
32+
// Subtract 1 because "xx\n".split("\n") => [ 'xx', '' ].
33+
const lines = fs.readFileSync(report, 'utf8').split('\n').length - 1;
34+
assert.strictEqual(lines, 1);
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
// Testcases for situations involving fatal errors, like Javascript heap OOM
4+
5+
require('../common');
6+
const assert = require('assert');
7+
const fs = require('fs');
8+
const helper = require('../common/report.js');
9+
const spawnSync = require('child_process').spawnSync;
10+
const tmpdir = require('../common/tmpdir');
11+
const fixtures = require('../common/fixtures');
12+
13+
// Common args that will cause an out-of-memory error for child process.
14+
const ARGS = [
15+
'--max-old-space-size=20',
16+
fixtures.path('report-oom'),
17+
];
18+
19+
{
20+
// Verify that --report-directory is respected when set.
21+
// Verify that --report-compact is respected when not set.
22+
tmpdir.refresh();
23+
const dir = '--report-directory=' + tmpdir.path;
24+
const args = ['--report-on-fatalerror', dir, ...ARGS];
25+
const child = spawnSync(process.execPath, args, { });
26+
assert.notStrictEqual(child.status, 0, 'Process exited unexpectedly');
27+
28+
const reports = helper.findReports(child.pid, tmpdir.path);
29+
assert.strictEqual(reports.length, 1);
30+
31+
const report = reports[0];
32+
helper.validate(report);
33+
assert.strictEqual(require(report).header.threadId, null);
34+
const lines = fs.readFileSync(report, 'utf8').split('\n').length - 1;
35+
assert(lines > 10);
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
// Testcases for situations involving fatal errors, like Javascript heap OOM
4+
5+
require('../common');
6+
const assert = require('assert');
7+
const helper = require('../common/report.js');
8+
const spawnSync = require('child_process').spawnSync;
9+
const tmpdir = require('../common/tmpdir');
10+
const fixtures = require('../common/fixtures');
11+
12+
// Common args that will cause an out-of-memory error for child process.
13+
const ARGS = [
14+
'--max-old-space-size=20',
15+
fixtures.path('report-oom'),
16+
];
17+
18+
{
19+
// Verify that --report-compact is respected when set.
20+
// Verify that --report-filename is respected when set.
21+
tmpdir.refresh();
22+
const args = [
23+
'--report-on-fatalerror',
24+
'--report-compact',
25+
'--report-filename=stderr',
26+
...ARGS,
27+
];
28+
const child = spawnSync(process.execPath, args, { encoding: 'utf8' });
29+
assert.notStrictEqual(child.status, 0, 'Process exited unexpectedly');
30+
31+
const reports = helper.findReports(child.pid, tmpdir.path);
32+
assert.strictEqual(reports.length, 0);
33+
34+
const lines = child.stderr.split('\n');
35+
// Skip over unavoidable free-form output and gc log from V8.
36+
const report = lines.find((i) => i.startsWith('{'));
37+
const json = JSON.parse(report);
38+
39+
assert.strictEqual(json.header.threadId, null);
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
// Testcases for situations involving fatal errors, like Javascript heap OOM
4+
5+
require('../common');
6+
const assert = require('assert');
7+
const helper = require('../common/report.js');
8+
const spawnSync = require('child_process').spawnSync;
9+
const tmpdir = require('../common/tmpdir');
10+
const fixtures = require('../common/fixtures');
11+
12+
// Common args that will cause an out-of-memory error for child process.
13+
const ARGS = [
14+
'--max-old-space-size=20',
15+
fixtures.path('report-oom'),
16+
];
17+
18+
{
19+
tmpdir.refresh();
20+
// Verify that --report-on-fatalerror is respected when not set.
21+
const args = ARGS;
22+
const child = spawnSync(process.execPath, args, { cwd: tmpdir.path });
23+
assert.notStrictEqual(child.status, 0, 'Process exited unexpectedly');
24+
const reports = helper.findReports(child.pid, tmpdir.path);
25+
assert.strictEqual(reports.length, 0);
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
// Testcases for situations involving fatal errors, like Javascript heap OOM
4+
5+
require('../common');
6+
const assert = require('assert');
7+
const helper = require('../common/report.js');
8+
const spawnSync = require('child_process').spawnSync;
9+
const tmpdir = require('../common/tmpdir');
10+
const fixtures = require('../common/fixtures');
11+
12+
// Common args that will cause an out-of-memory error for child process.
13+
const ARGS = [
14+
'--max-old-space-size=20',
15+
fixtures.path('report-oom'),
16+
];
17+
18+
{
19+
// Verify that --report-on-fatalerror is respected when set.
20+
tmpdir.refresh();
21+
const args = ['--report-on-fatalerror', ...ARGS];
22+
const child = spawnSync(process.execPath, args, { cwd: tmpdir.path });
23+
assert.notStrictEqual(child.status, 0, 'Process exited unexpectedly');
24+
25+
const reports = helper.findReports(child.pid, tmpdir.path);
26+
assert.strictEqual(reports.length, 1);
27+
28+
const report = reports[0];
29+
helper.validate(report);
30+
31+
const content = require(report);
32+
// Errors occur in a context where env is not available, so thread ID is
33+
// unknown. Assert this, to verify that the underlying env-less situation is
34+
// actually reached.
35+
assert.strictEqual(content.header.threadId, null);
36+
assert.strictEqual(content.header.trigger, 'OOMError');
37+
}

test/report/test-report-fatalerror-oomerror.js

-123
This file was deleted.

0 commit comments

Comments
 (0)