|
1 | 1 | // Flags: --expose-internals |
2 | 2 | 'use strict'; |
3 | | -const common = require('../common'); |
| 3 | +require('../common'); |
| 4 | + |
| 5 | +const { test } = require('node:test'); |
| 6 | +const { Worker } = require('node:worker_threads'); |
| 7 | +const { once } = require('node:events'); |
4 | 8 | const { recordState } = require('../common/heap'); |
5 | | -const { Worker } = require('worker_threads'); |
6 | | -const { once } = require('events'); |
7 | 9 |
|
8 | | -(async function() { |
9 | | - const w = new Worker('setInterval(() => {}, 100)', { eval: true }); |
| 10 | +test('Worker threads heap snapshot validation', async (t) => { |
| 11 | + await t.test('should validate heap snapshot structure for MessagePort', async () => { |
| 12 | + const w = new Worker('setInterval(() => {}, 100)', { eval: true }); |
| 13 | + |
| 14 | + // Wait for the Worker to be online |
| 15 | + await once(w, 'online'); |
10 | 16 |
|
11 | | - await once(w, 'online'); |
12 | | - const stream = await w.getHeapSnapshot(); |
13 | | - const snapshot = recordState(stream); |
14 | | - snapshot.validateSnapshot('Node / MessagePort', [ |
15 | | - { |
16 | | - children: [ |
17 | | - { node_name: 'Node / MessagePortData', edge_name: 'data' }, |
| 17 | + // Generate heap snapshot |
| 18 | + const stream = await w.getHeapSnapshot(); |
| 19 | + const snapshot = recordState(stream); |
| 20 | + |
| 21 | + // Validate the snapshot |
| 22 | + snapshot.validateSnapshot( |
| 23 | + 'Node / MessagePort', |
| 24 | + [ |
| 25 | + { |
| 26 | + children: [ |
| 27 | + { node_name: 'Node / MessagePortData', edge_name: 'data' }, |
| 28 | + ], |
| 29 | + }, |
18 | 30 | ], |
19 | | - }, |
20 | | - ], { loose: true }); |
21 | | - await w.terminate(); |
22 | | -})().then(common.mustCall()); |
| 31 | + { loose: true }, |
| 32 | + ); |
| 33 | + |
| 34 | + // Terminate the Worker |
| 35 | + await w.terminate(); |
| 36 | + }); |
| 37 | +}); |
0 commit comments