-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Include listen errors in app.listen() callback #2623
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
Changes from all commits
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
|
||
var express = require('../') | ||
, assert = require('assert') | ||
, request = require('supertest'); | ||
|
||
describe('app.listen()', function(){ | ||
|
@@ -15,4 +16,18 @@ describe('app.listen()', function(){ | |
done(); | ||
}); | ||
}) | ||
|
||
it('should callback on HTTP server errors', function(done){ | ||
var app = express(); | ||
var app2 = express(); | ||
|
||
var server = app.listen(9999, function(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. Can this port number be made dynamic? Getting some race conditions where the Express suite is running multiples times on the same machine and they all want to use port 9999. Just 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. Yeah, I can make this change for sure. Let me know if you also want me to move this PR to the 5.0 branch and I will do it all at once. |
||
assert(err === undefined); | ||
app2.listen(9999, function(err){ | ||
assert(err.code === 'EADDRINUSE'); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}) | ||
}) |
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.
Neat, I found an even simpler/more robust solution to this: call
.listen
and just see if there is now alistening
event listener attached, and use that :)