• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3require('../common');
4const tmpdir = require('../common/tmpdir');
5const assert = require('assert');
6const { spawnSync } = require('child_process');
7const fixtures = require('../common/fixtures');
8const fs = require('fs');
9const env = {
10  ...process.env,
11  NODE_DEBUG_NATIVE: 'diagnostics'
12};
13
14{
15  tmpdir.refresh();
16  const child = spawnSync(process.execPath, [
17    fixtures.path('workload', 'grow-worker.js'),
18  ], {
19    cwd: tmpdir.path,
20    env: {
21      TEST_SNAPSHOTS: 1,
22      TEST_OLD_SPACE_SIZE: 50,
23      ...env
24    }
25  });
26  console.log(child.stdout.toString());
27  const stderr = child.stderr.toString();
28  console.log(stderr);
29  const risky = /Not generating snapshots because it's too risky/.test(stderr);
30  if (!risky) {
31    // There should be one snapshot taken and then after the
32    // snapshot heap limit callback is popped, the OOM callback
33    // becomes effective.
34    assert(stderr.includes('ERR_WORKER_OUT_OF_MEMORY'));
35    const list = fs.readdirSync(tmpdir.path)
36      .filter((file) => file.endsWith('.heapsnapshot'));
37    assert.strictEqual(list.length, 1);
38  }
39}
40