-
Notifications
You must be signed in to change notification settings - Fork 983
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
fix(server): address Node v10.x req close event firing order #1672
Changes from all commits
929f9a1
b237d3e
99bc0bf
c54c3c1
5996573
245a91d
f82c3a6
b84caa8
4e8e5de
6cb9fc7
ee3b338
df356c9
10410fb
def6164
3d0bd42
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
// external requires | ||
var assert = require('chai').assert; | ||
|
||
var restify = require('../../lib/index.js'); | ||
var restifyClients = require('restify-clients'); | ||
|
||
|
@@ -27,8 +28,7 @@ describe('request metrics plugin', function() { | |
CLIENT = restifyClients.createJsonClient({ | ||
url: 'http://127.0.0.1:' + PORT, | ||
dtrace: helper.dtrace, | ||
retry: false, | ||
requestTimeout: 200 | ||
retry: false | ||
}); | ||
|
||
done(); | ||
|
@@ -103,6 +103,7 @@ describe('request metrics plugin', function() { | |
it('should return metrics with pre error', function(done) { | ||
SERVER.on('uncaughtException', function(req, res, route, err) { | ||
assert.ok(err); | ||
res.send(err); | ||
}); | ||
|
||
SERVER.on( | ||
|
@@ -139,6 +140,7 @@ describe('request metrics plugin', function() { | |
it('should return metrics with use error', function(done) { | ||
SERVER.on('uncaughtException', function(req, res, route, err) { | ||
assert.ok(err); | ||
res.send(err); | ||
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. Same question regarding 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. see comment above |
||
}); | ||
|
||
SERVER.on( | ||
|
@@ -242,11 +244,17 @@ describe('request metrics plugin', function() { | |
} | ||
); | ||
|
||
CLIENT.get('/foo?a=1', function(err, _, res) { | ||
// request should timeout | ||
assert.ok(err); | ||
assert.equal(err.name, 'RequestTimeoutError'); | ||
}); | ||
CLIENT.get( | ||
{ | ||
path: '/foo?a=1', | ||
requestTimeout: 200 | ||
}, | ||
function(err, _, res) { | ||
// request should timeout | ||
assert.ok(err); | ||
assert.equal(err.name, 'RequestTimeoutError'); | ||
} | ||
); | ||
}); | ||
|
||
it('should handle uncaught exceptions', function(done) { | ||
|
@@ -260,6 +268,7 @@ describe('request metrics plugin', function() { | |
{ | ||
server: SERVER | ||
}, | ||
// TODO: test timeouts if any of the following asserts fails | ||
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 we file a corresponding issue? |
||
function(err, metrics, req, res, route) { | ||
assert.ok(err); | ||
assert.equal(err.name, 'Error'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1934,6 +1934,29 @@ test("should emit 'after' on successful request", function(t) { | |
}); | ||
}); | ||
|
||
test("should emit 'after' on successful request with work", function(t) { | ||
SERVER.on('after', function(req, res, route, err) { | ||
t.ifError(err); | ||
t.end(); | ||
}); | ||
|
||
SERVER.get('/foobar', function(req, res, next) { | ||
// with timeouts we are testing that request lifecycle | ||
// events are firing in the correct order | ||
setTimeout(function() { | ||
res.send('hello world'); | ||
setTimeout(function() { | ||
next(); | ||
}, 500); | ||
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. Why do we need any 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. We generate some "work" in the server to be sure that events are firing in the right order. In my previous fix tests passed with positive false. 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.
EDIT: I get it now: we want to send the response and call the Why not keeping the original test? Should be add a new test instead of replacing the existing one? 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. Remaining questions above still relevant:
|
||
}, 500); | ||
}); | ||
|
||
CLIENT.get('/foobar', function(err, _, res) { | ||
t.ifError(err); | ||
t.equal(res.statusCode, 200); | ||
}); | ||
}); | ||
|
||
test("should emit 'after' on errored request", function(t) { | ||
SERVER.on('after', function(req, res, route, err) { | ||
t.ok(err); | ||
|
@@ -1995,6 +2018,7 @@ test( | |
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, 'RequestCloseError'); | ||
t.end(); | ||
}); | ||
|
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.
Is there any exception thrown in this test? It doesn't seem so, it seems there's only an error being passed to a handler's
next
callback? If so, why does the server emit'uncaughtException'
?Also, why do we need to
res.send()
now when we wouldn't need to do it before?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.
So it should have been there
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.
So in this test before your changes we would call
done()
because the'after'
event would be emitted no matter what, but we wouldn't execute the assertions in the client's request's callback?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.
yes