-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
test: migrate tests to use node:test module for better test structure for report worker #56038
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
Closed
mertcanaltin
wants to merge
3
commits into
nodejs:main
from
mertcanaltin:test/refactor-report-worker
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,48 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const { Worker } = require('worker_threads'); | ||
| const { once } = require('events'); | ||
| const helper = require('../common/report'); | ||
|
|
||
| async function basic() { | ||
| // Test that the report includes basic information about Worker threads. | ||
|
|
||
| const w = new Worker(` | ||
| const { parentPort } = require('worker_threads'); | ||
| parentPort.once('message', () => { | ||
| /* Wait for message to stop the Worker */ | ||
| }); | ||
| `, { eval: true }); | ||
|
|
||
| await once(w, 'online'); | ||
|
|
||
| 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({}); | ||
|
|
||
| await once(w, 'exit'); | ||
| } | ||
| require('../common'); | ||
|
|
||
| async function interruptingJS() { | ||
| // Test that the report also works when Worker threads are busy in JS land. | ||
|
|
||
| const w = new Worker('while (true);', { eval: true }); | ||
|
|
||
| await once(w, 'online'); | ||
|
|
||
| const report = process.report.getReport(); | ||
| helper.validateContent(report); | ||
| assert.strictEqual(report.workers.length, 1); | ||
| helper.validateContent(report.workers[0]); | ||
|
|
||
| await w.terminate(); | ||
| } | ||
|
|
||
| (async function() { | ||
| await basic(); | ||
| await interruptingJS(); | ||
| })().then(common.mustCall()); | ||
| const helper = require('../common/report'); | ||
| const assert = require('node:assert'); | ||
| const { test } = require('node:test'); | ||
| const { Worker } = require('node:worker_threads'); | ||
| const { once } = require('node:events'); | ||
|
|
||
| test('Worker threads report basic information', async (t) => { | ||
| await t.test('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 }); | ||
|
|
||
| await once(w, 'online'); | ||
|
|
||
| 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'; | ||
| assert.strictEqual(report.workers.length, 1, workerLengthMessage); | ||
| helper.validateContent(report.workers[0]); | ||
| assert.strictEqual(report.workers[0].header.threadId, w.threadId, threadIdMessage); | ||
|
|
||
| w.postMessage({}); | ||
|
|
||
| await once(w, 'exit'); | ||
| }); | ||
|
|
||
| await t.test('should generate report when Workers are busy in JS land', async () => { | ||
| const w = new Worker('while (true);', { eval: true }); | ||
|
|
||
| await once(w, 'online'); | ||
|
|
||
| const report = process.report.getReport(); | ||
| helper.validateContent(report); | ||
| const workerLengthMessage = 'Report should include one Worker'; | ||
| assert.strictEqual(report.workers.length, 1, workerLengthMessage); | ||
| helper.validateContent(report.workers[0]); | ||
|
|
||
| await w.terminate(); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could we also use
describe/itto avoid usingawait t.test?Not entirely sure about this: could we set
concurrency: true, or is sequentiality needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed what you said, thank you, the test is more readable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope I understood correctly, when I used --test-concurrency I saw that the tests were successfully synchronized