Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
worker: improve code coverage for getHeapSnapshot
  • Loading branch information
ErickWendel committed Feb 1, 2022
commit 0a3e3c705f42ae4e1c012b5f983a368045c3a221
1 change: 1 addition & 0 deletions lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ function eventLoopUtilization(util1, util2) {
}

module.exports = {
kHandle,
Comment thread
ErickWendel marked this conversation as resolved.
Outdated
ownsProcessState,
isMainThread,
SHARE_ENV,
Expand Down
22 changes: 22 additions & 0 deletions test/parallel/test-worker-heap-snapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

// Flags: --expose-internals
const common = require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');
const { HeapSnapshotStream } = require('internal/heap_utils');
const { kHandle } = require('internal/worker');

const worker = new Worker(__filename);
Comment thread
ErickWendel marked this conversation as resolved.
Outdated
const snapShotResult = { ondone: () => {} };
worker[kHandle].takeHeapSnapshot = common.mustCall(() => snapShotResult);

worker.on('online', () => {
Comment thread
ErickWendel marked this conversation as resolved.
Outdated
const snapShotResponse = worker.getHeapSnapshot();
snapShotResult.ondone({});

snapShotResponse.then(common.mustCall((heapSnapshotStream) => {
assert.ok(heapSnapshotStream instanceof HeapSnapshotStream);
Comment thread
ErickWendel marked this conversation as resolved.
Outdated
worker.terminate();
}));
});