Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

worker: improve code coverage #41818

Merged
merged 4 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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,
ErickWendel marked this conversation as resolved.
Show resolved Hide resolved
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);
ErickWendel marked this conversation as resolved.
Show resolved Hide resolved
const snapShotResult = { ondone: () => {} };
worker[kHandle].takeHeapSnapshot = common.mustCall(() => snapShotResult);

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

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