11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled(); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 71cb0ef41Sopenharmony_ciconst startCLI = require('../common/debugger'); 81cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 91cb0ef41Sopenharmony_ciconst path = require('path'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_citmpdir.refresh(); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst { readFileSync } = require('fs'); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciconst filename = path.join(tmpdir.path, 'node.heapsnapshot'); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci// Heap profiler take snapshot. 181cb0ef41Sopenharmony_ci{ 191cb0ef41Sopenharmony_ci const opts = { cwd: tmpdir.path }; 201cb0ef41Sopenharmony_ci const cli = startCLI(['--port=0', fixtures.path('debugger/empty.js')], [], opts); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci async function waitInitialBreak() { 231cb0ef41Sopenharmony_ci try { 241cb0ef41Sopenharmony_ci await cli.waitForInitialBreak(); 251cb0ef41Sopenharmony_ci await cli.waitForPrompt(); 261cb0ef41Sopenharmony_ci await cli.command('takeHeapSnapshot()'); 271cb0ef41Sopenharmony_ci JSON.parse(readFileSync(filename, 'utf8')); 281cb0ef41Sopenharmony_ci // Check that two simultaneous snapshots don't step all over each other. 291cb0ef41Sopenharmony_ci // Refs: https://github.com/nodejs/node/issues/39555 301cb0ef41Sopenharmony_ci await cli.command('takeHeapSnapshot(); takeHeapSnapshot()'); 311cb0ef41Sopenharmony_ci JSON.parse(readFileSync(filename, 'utf8')); 321cb0ef41Sopenharmony_ci } finally { 331cb0ef41Sopenharmony_ci await cli.quit(); 341cb0ef41Sopenharmony_ci } 351cb0ef41Sopenharmony_ci } 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci // Check that the snapshot is valid JSON. 381cb0ef41Sopenharmony_ci waitInitialBreak().then(common.mustCall()); 391cb0ef41Sopenharmony_ci} 40