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
feat: provide callback to uncaughtException handler #1766
Changes from 1 commit
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 |
---|---|---|
|
@@ -2051,6 +2051,34 @@ test( | |
} | ||
); | ||
|
||
// eslint-disable-next-line max-len | ||
test("should emit 'after' on client closed request with an uncaughtException", function(t) { | ||
SERVER.on('after', function(req, res, route, err) { | ||
t.ok(err); | ||
t.equal(req.connectionState(), 'close'); | ||
t.equal(res.statusCode, 444); | ||
t.equal(err.name, 'Error'); | ||
t.end(); | ||
}); | ||
|
||
SERVER.on('uncaughtException', function(req, res, route, err, next) { | ||
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. In the documentation, I would suggest not calling that callback |
||
next(); | ||
}); | ||
|
||
SERVER.get('/foobar', function(req, res, next) { | ||
// fast client times out at 500ms, wait for 800ms which should cause | ||
// client to timeout | ||
setTimeout(function() { | ||
throw new Error('foo'); | ||
}, 800); | ||
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. Can we rely on a 'timeout' event on Otherwise it seems this test could be broken easily by changes in the client's implementation details. 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. Could do, I mostly copied this pattern from existing tests so I'm not sure if you'd prefer consistency with those tests over stability for this test? 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 prefer stability here. Your stable test can act as a good example of how to correctly write tests and that pattern can then be used for future tests. I think changing the other tests to follow your pattern of stable tests can also be a good first issue for new contributors. 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. @cprussin @rajatkumar I refactored the test so that it doesn't rely on any arbitrary timeout, but instead relies on the actual state of the request/response lifecycle. Let me know if that looks good to you! |
||
}); | ||
|
||
FAST_CLIENT.get('/foobar', function(err, _, res) { | ||
t.ok(err); | ||
t.equal(err.name, 'RequestTimeoutError'); | ||
}); | ||
}); | ||
|
||
test('should increment/decrement inflight request count', function(t) { | ||
SERVER.get('/foo', function(req, res, next) { | ||
t.equal(SERVER.inflightRequests(), 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.
Please put a comment about the why here and describe what will happen with and without domains.
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.
+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.
@hekike @rajatkumar Added some comments here, let me know if that addresses your feedback!