Skip to content

Commit

Permalink
test: improve worker_threads coverage
Browse files Browse the repository at this point in the history
PR-URL: #41818
Refs: https://coverage.nodejs.org/coverage-7123a00b03a90862/lib/internal/worker.js.html#L412
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
ErickWendel authored and juanarbol committed May 31, 2022
1 parent 1d1ca20 commit b96cfde
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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
16 changes: 16 additions & 0 deletions test/parallel/test-worker-heap-snapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');
const { once } = require('events');

// Ensure that worker.getHeapSnapshot() returns a valid JSON
(async () => {
const worker = new Worker('setInterval(() => {}, 1000);', { eval: true });
await once(worker, 'online');
const stream = await worker.getHeapSnapshot();
assert.ok(JSON.parse(stream.read()));

await worker.terminate();
})().then(common.mustCall());

0 comments on commit b96cfde

Please sign in to comment.