-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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: add test cases for setUnrefTimeout. #20945
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
50d63c9
test: add test cases for setUnrefTimeout.
kakts 0822c0f
test: refactored some test cases for setUnrefTimeout.
kakts 0d639ea
test: deleted notStrictEqual.
kakts 6436008
test: refactored some test cases for setUnrefTimeout.
kakts 64e15a7
test: refactor test-timers-setunreftimeout.js
kakts a5570d9
fix: refactor test/parallel/test-timers-setunreftimeout.js .
kakts e756201
fix: lint error in test/parallel/test-timers-setunreftimeout.js
kakts 90daaa9
test: refactor test/parallel/test-timers-setunreftimeout.js
kakts b1f3a85
test: fix comment and refactor a test case in test/parallel/test-time…
kakts ce868dd
test: refactor test case for timers.setUnrefTimeout
kakts a92b4d8
test: capitalize the words in setunreftimeout.
kakts 27ebac4
test: fix ERR_INVALID_CALLBACK message in setunreftimeout.
kakts 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 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const { strictEqual } = require('assert'); | ||
const { setUnrefTimeout } = require('internal/timers'); | ||
|
||
{ | ||
common.expectsError( | ||
() => setUnrefTimeout(), | ||
{ | ||
code: 'ERR_INVALID_CALLBACK', | ||
type: TypeError, | ||
message: 'Callback must be a function. Received undefined' | ||
} | ||
); | ||
} | ||
|
||
// Test that setUnrefTimeout correctly passes arguments to the callback | ||
{ | ||
const maxArgsNum = 4; | ||
for (let i = 0; i < maxArgsNum; i++) { | ||
const inputArgs = []; | ||
// Set the input argument params | ||
for (let j = 0; j <= i; j++) { | ||
inputArgs.push(j); | ||
} | ||
|
||
const timer = setUnrefTimeout(common.mustCall((...args) => { | ||
// Check the number of arguments passed to this callback. | ||
strictEqual(args.length, i + 1, | ||
`arguments.length should be ${i + 1}.` + | ||
`actual ${args.length}` | ||
); | ||
for (let k = 0; k < maxArgsNum; k++) { | ||
// Checking the arguments passed to setUnrefTimeout | ||
const expected = (k <= i) ? inputArgs[k] : undefined; | ||
strictEqual(args[k], expected, | ||
`result ${k} should be ${expected}.` + | ||
`actual ${args[k]}`); | ||
} | ||
clearTimeout(timer); | ||
}), 1, ...inputArgs); | ||
|
||
setTimeout(common.mustCall(), 1); | ||
} | ||
} |
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.
Instead of populating results, just do the check in the first timeout. Then this timeout shouldn't have a body. Literally just
const testTimer = setTimeout(common.mustCall(), 1);
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.
Thank you!
I've fixed it.