Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
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,
ownsProcessState,
isMainThread,
SHARE_ENV,
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-worker-environmentdata.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
// Flags: --expose-internals

require('../common');
const {
Expand All @@ -8,6 +9,8 @@ const {
threadId,
} = require('worker_threads');

const { assignEnvironmentData } = require('internal/worker');

const {
deepStrictEqual,
strictEqual,
Expand All @@ -26,6 +29,8 @@ if (!process.env.HAS_STARTED_WORKER) {
strictEqual(getEnvironmentData('foo'), 'bar');
deepStrictEqual(getEnvironmentData('hello'), { value: 'world' });
strictEqual(getEnvironmentData(1), undefined);
assignEnvironmentData(undefined); // It won't setup any key.
strictEqual(getEnvironmentData(undefined), undefined);

// Recurse to make sure the environment data is inherited
if (threadId <= 2)
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);
const snapShotResult = { ondone: () => {} };
worker[kHandle].takeHeapSnapshot = common.mustCall(() => snapShotResult);

worker.on('online', () => {
const snapShotResponse = worker.getHeapSnapshot();
snapShotResult.ondone({});

snapShotResponse.then(common.mustCall((heapSnapshotStream) => {
assert.ok(heapSnapshotStream instanceof HeapSnapshotStream);
worker.terminate();
}));
});