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