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

test: migrate tests to use node:test module for better test structure for report worker #56038

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
73 changes: 38 additions & 35 deletions test/report/test-report-worker.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');
const { once } = require('events');

require('../common');

const helper = require('../common/report');
const assert = require('node:assert');
const { describe, it } = require('node:test');
const { Worker } = require('node:worker_threads');
const { once } = require('node:events');

describe('Worker threads', () => {
it('should include basic information about Worker threads', async () => {
const w = new Worker(`
const { parentPort } = require('worker_threads');
parentPort.once('message', () => {
/* Wait for message to stop the Worker */
});
`, { eval: true });

async function basic() {
// Test that the report includes basic information about Worker threads.
await once(w, 'online');

const w = new Worker(`
const { parentPort } = require('worker_threads');
parentPort.once('message', () => {
/* Wait for message to stop the Worker */
});
`, { eval: true });
const report = process.report.getReport();
helper.validateContent(report);
const workerLengthMessage = 'Report should include one Worker';
const threadIdMessage = 'Thread ID should match the Worker thread ID';

await once(w, 'online');
assert.strictEqual(report.workers.length, 1, workerLengthMessage);
helper.validateContent(report.workers[0]);
assert.strictEqual(report.workers[0].header.threadId, w.threadId, threadIdMessage);

const report = process.report.getReport();
helper.validateContent(report);
assert.strictEqual(report.workers.length, 1);
helper.validateContent(report.workers[0]);
assert.strictEqual(report.workers[0].header.threadId, w.threadId);

w.postMessage({});
w.postMessage({});

await once(w, 'exit');
}

async function interruptingJS() {
// Test that the report also works when Worker threads are busy in JS land.
await once(w, 'exit');
});

const w = new Worker('while (true);', { eval: true });
it('should generate report when Workers are busy in JS land', async () => {
const w = new Worker('while (true);', { eval: true });

await once(w, 'online');
await once(w, 'online');

const report = process.report.getReport();
helper.validateContent(report);
assert.strictEqual(report.workers.length, 1);
helper.validateContent(report.workers[0]);
const report = process.report.getReport();
helper.validateContent(report);
const workerLengthMessage = 'Report should include one Worker';

await w.terminate();
}
assert.strictEqual(report.workers.length, 1, workerLengthMessage);
helper.validateContent(report.workers[0]);

(async function() {
await basic();
await interruptingJS();
})().then(common.mustCall());
await w.terminate();
});
});
Loading