-
Notifications
You must be signed in to change notification settings - Fork 29.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
Changes from 9 commits
50d63c9
0822c0f
0d639ea
6436008
64e15a7
a5570d9
e756201
90daaa9
b1f3a85
ce868dd
a92b4d8
27ebac4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,54 @@ | ||||||
// 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' | ||||||
} | ||||||
); | ||||||
} | ||||||
|
||||||
// Test that setUnrefTimeout correctly passes arguments to the callback | ||||||
{ | ||||||
const maxArgsNum = 4; | ||||||
for (let i = 0; i < maxArgsNum; i++) { | ||||||
const results = []; | ||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Linter wants this to be capitalized (
Suggested change
|
||||||
strictEqual(args.length, i + 1, | ||||||
`arguments.length should be ${i + 1}.` + | ||||||
`actual ${args.length}` | ||||||
); | ||||||
for (const arg of args) { | ||||||
results.push(arg); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just check the results here instead of populating an array. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. I'll fix not populating an array. |
||||||
} | ||||||
}), 1, ...inputArgs); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! But if I fix this as you requested, it occures an error. |
||||||
|
||||||
const testTimer = setTimeout(common.mustCall(() => { | ||||||
for (let k = 0; k < maxArgsNum; k++) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! |
||||||
// Checking the arguments passed to setUnrefTimeout | ||||||
const expected = (k <= i) ? inputArgs[k] : undefined; | ||||||
strictEqual(results[k], expected, | ||||||
`result ${k} should be ${expected}.` + | ||||||
`actual ${inputArgs[k]}`); | ||||||
} | ||||||
clearTimeout(testTimer); | ||||||
clearTimeout(timer); | ||||||
}), 100); | ||||||
} | ||||||
} |
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.
Linter wants this to be capitalized (
make -j4 lint
)