-
Notifications
You must be signed in to change notification settings - Fork 41
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
add timeout support for kill()
#51
Conversation
918f0eb
to
6efec76
Compare
6efec76
to
5dc26aa
Compare
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.
Looks good from my end. I left some suggestions for improvements, but overall it looks like this should work. Thanks for taking the time to help us out!
test/test.js
Outdated
}); | ||
}); | ||
}); | ||
}); |
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's a little annoying for the test to have to wait the default 30 seconds. I get why you want to cover this case though. I would have been okay with a 5 or 10 second timeout to be honest.
test/test.js
Outdated
var killStartDate = Date.now(); | ||
PS.lookup({pid: pid}, function (err, list) { | ||
assert.equal(list.length, 1); | ||
PS.kill(pid, { timeout: 5 }, function (err) { |
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.
Picking a lower number here would make tests faster.
}); | ||
} | ||
|
||
next && checkKilled(next); | ||
|
||
checkTimeoutTimer = next && setTimeout(function() { |
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.
Using setTimeout here seems a little overkill. You could just remember a timestamp when the killing started, then compare the current timestamp against that inside the recursion. That would remove the need for the two variables to keep track of timing out.
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.
That sounds doable and easier to implement, will try : )
It probably makes sense to bring in something like sinon so you can manually control the clock instead of waiting. This will make tests faster and less flakey. Look at sinon.useFakeTimers. |
@lencioni That's a good suggestion, will try : ) |
@lencioni @trotzig thanks for reviewing this PR and your suggestions, I will do some optimization based on your suggestions, should be easy. The problem I am facing now is the test cases randomly fails, I put some logs to Travis-CI, it seems like that the result of the process checking is not stable, for the timeout test cases for You can see here https://travis-ci.org/neekey/ps/jobs/217466603#L340, so the randomly false checking result causes the test case failed. That's just very weird and I have to say it happens before that's why there is a Do you guys have any idea about this? Otherwise, I will keep on debugging on it until I can fix it. |
I did more debugging, and found somehow in the Travis machine, sometime's the This happens only for node 5 and 0.12 |
401551a
to
d6efd81
Compare
What
Add timeout for
kill()
function. Now by default the timeout will be 30s, if the killing is not successful after 30s, the callback will be invoked with an timeout error, you can also manually set a timeout value (as seconds):