File: test-heapdump-flag-custom-dir.js

package info (click to toggle)
nodejs 20.19.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 219,072 kB
  • sloc: cpp: 1,277,408; javascript: 565,332; ansic: 129,476; python: 58,536; sh: 3,841; makefile: 2,725; asm: 1,732; perl: 248; lisp: 222; xml: 42
file content (50 lines) | stat: -rw-r--r-- 1,499 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
const common = require('../common');


if (common.isWindows)
  common.skip('test not supported on Windows');

const assert = require('assert');

const validateHeapSnapshotFile = () => {
  const fs = require('fs');

  assert.strictEqual(process.listenerCount('SIGUSR2'), 1);
  process.kill(process.pid, 'SIGUSR2');
  process.kill(process.pid, 'SIGUSR2');

  // Asynchronously wait for the snapshot. Use an async loop to be a bit more
  // robust in case platform or machine differences throw off the timing.
  (function validate() {
    const files = fs.readdirSync(process.cwd());

    if (files.length === 0)
      return setImmediate(validate);

    assert.strictEqual(files.length, 2);

    for (let i = 0; i < files.length; i++) {
      assert.match(files[i], /^Heap\..+\.heapsnapshot$/);

      // Check the file is parsable as JSON
      JSON.parse(fs.readFileSync(files[i]));
    }
  })();
};

if (process.argv[2] === 'child') {
  validateHeapSnapshotFile();
} else {
  // Modify the timezone. So we can check the file date string still returning correctly.
  process.env.TZ = 'America/New_York';
  const { spawnSync } = require('child_process');
  const tmpdir = require('../common/tmpdir');

  tmpdir.refresh();
  const args = ['--heapsnapshot-signal', 'SIGUSR2', '--diagnostic-dir', tmpdir.path, __filename, 'child'];
  const child = spawnSync(process.execPath, args, { cwd: tmpdir.path });

  assert.strictEqual(child.status, 0);
  assert.strictEqual(child.signal, null);
}