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 all 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
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope this one isn't flaky like the other one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benjamingr @Trott which one was that? I was talking with @ErickWendel today and I might have some idea of what the problem was/is

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it was already fixed #41204 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, that test is actually very very similar to this one. That also means that I’m wrong about having an idea about the cause of the flakiness :)

assert.ok(JSON.parse(stream.read()));

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