-
Notifications
You must be signed in to change notification settings - Fork 30.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
timers: assorted cleanup + improvements #18486
Changes from all commits
0f0304b
cdf6da5
8c6953d
987d96e
4dacb85
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,17 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
process.once('uncaughtException', common.expectsError({ | ||
message: 'Timeout Error' | ||
})); | ||
|
||
let called = false; | ||
const t = setTimeout(() => { | ||
assert(!called); | ||
called = true; | ||
t.ref(); | ||
throw new Error('Timeout Error'); | ||
}, 1).unref(); | ||
|
||
setTimeout(common.mustCall(), 1); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,16 @@ const t = setInterval(() => { | |
cntr++; | ||
if (cntr === 1) { | ||
common.busyLoop(100); | ||
// ensure that the event loop passes before the second interval | ||
setImmediate(() => assert.strictEqual(cntr, 1)); | ||
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. Should these new callbacks also have 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. I opted not to include since 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. Mmm yes but I'm not sure that's guaranteed to be true for all APIs so we do need to be careful about that path of doing things, |
||
first = Timer.now(); | ||
} else if (cntr === 2) { | ||
assert(Timer.now() - first < 100); | ||
clearInterval(t); | ||
} | ||
}, 100); | ||
const t2 = setInterval(() => { | ||
if (cntr === 2) { | ||
clearInterval(t2); | ||
} | ||
}, 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.
common.mustCall()
doesn't work here? It checks for one and only one call by default.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.
It can potentially cause an infinite loop since it only checks at
exit
and this tests the fact that callingref
onunref'd
handle doesn't cause the C++ loop to continue forever.This is related to the
owner
check in C++. Someone could, in the future, think to optimize that by checking whether the handle isref
orunref
, instead of checking for presence of anowner
, but that would actually be incorrect and would cause an infinite loop on this test.