11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_cirequire('../common'); 41cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process'); 71cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 81cb0ef41Sopenharmony_ciconst fs = require('fs'); 91cb0ef41Sopenharmony_ciconst env = { 101cb0ef41Sopenharmony_ci ...process.env, 111cb0ef41Sopenharmony_ci NODE_DEBUG_NATIVE: 'diagnostics' 121cb0ef41Sopenharmony_ci}; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci{ 151cb0ef41Sopenharmony_ci tmpdir.refresh(); 161cb0ef41Sopenharmony_ci const child = spawnSync(process.execPath, [ 171cb0ef41Sopenharmony_ci fixtures.path('workload', 'grow-worker.js'), 181cb0ef41Sopenharmony_ci ], { 191cb0ef41Sopenharmony_ci cwd: tmpdir.path, 201cb0ef41Sopenharmony_ci env: { 211cb0ef41Sopenharmony_ci TEST_SNAPSHOTS: 1, 221cb0ef41Sopenharmony_ci TEST_OLD_SPACE_SIZE: 50, 231cb0ef41Sopenharmony_ci ...env 241cb0ef41Sopenharmony_ci } 251cb0ef41Sopenharmony_ci }); 261cb0ef41Sopenharmony_ci console.log(child.stdout.toString()); 271cb0ef41Sopenharmony_ci const stderr = child.stderr.toString(); 281cb0ef41Sopenharmony_ci console.log(stderr); 291cb0ef41Sopenharmony_ci const risky = /Not generating snapshots because it's too risky/.test(stderr); 301cb0ef41Sopenharmony_ci if (!risky) { 311cb0ef41Sopenharmony_ci // There should be one snapshot taken and then after the 321cb0ef41Sopenharmony_ci // snapshot heap limit callback is popped, the OOM callback 331cb0ef41Sopenharmony_ci // becomes effective. 341cb0ef41Sopenharmony_ci assert(stderr.includes('ERR_WORKER_OUT_OF_MEMORY')); 351cb0ef41Sopenharmony_ci const list = fs.readdirSync(tmpdir.path) 361cb0ef41Sopenharmony_ci .filter((file) => file.endsWith('.heapsnapshot')); 371cb0ef41Sopenharmony_ci assert.strictEqual(list.length, 1); 381cb0ef41Sopenharmony_ci } 391cb0ef41Sopenharmony_ci} 40