nodejs/test/parallel/test-hash-seed.mjs
Michaël Zasso 20feebb452
src,test: add V8 API to test the hash seed
PR-URL: https://github.com/nodejs/node/pull/58070
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2025-05-02 15:10:37 +02:00

28 lines
821 B
JavaScript

import '../common/index.mjs';
import assert from 'node:assert';
import { execFile } from 'node:child_process';
import { promisify, debuglog } from 'node:util';
// This test verifies that the V8 hash seed is random
// and unique between child processes.
const execFilePromise = promisify(execFile);
const debug = debuglog('test');
const kRepetitions = 3;
const seeds = await Promise.all(Array.from({ length: kRepetitions }, generateSeed));
debug(`Seeds: ${seeds}`);
assert.strictEqual(new Set(seeds).size, seeds.length);
assert.strictEqual(seeds.length, kRepetitions);
async function generateSeed() {
const output = await execFilePromise(process.execPath, [
'--expose-internals',
'--print',
'require("internal/test/binding").internalBinding("v8").getHashSeed()',
]);
return output.stdout.trim();
}