|
| 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 | +} |
0 commit comments