mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test: improve worker_threads
coverage
PR-URL: https://github.com/nodejs/node/pull/41818 Refs: https://coverage.nodejs.org/coverage-7123a00b03a90862/lib/internal/worker.js.html#L412 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
3b338cfbe9
commit
ba5b5acaf1
@ -1,4 +1,5 @@
|
||||
'use strict';
|
||||
// Flags: --expose-internals
|
||||
|
||||
require('../common');
|
||||
const {
|
||||
@ -8,6 +9,8 @@ const {
|
||||
threadId,
|
||||
} = require('worker_threads');
|
||||
|
||||
const { assignEnvironmentData } = require('internal/worker');
|
||||
|
||||
const {
|
||||
deepStrictEqual,
|
||||
strictEqual,
|
||||
@ -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)
|
||||
|
16
test/parallel/test-worker-heap-snapshot.js
Normal file
16
test/parallel/test-worker-heap-snapshot.js
Normal file
@ -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());
|
Loading…
Reference in New Issue
Block a user