This repository has been archived by the owner on Feb 11, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 506
Catch http exception on server start #733
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
371a825
Merge pull request #1 from mcollina/master
martin-doyle 6db3d6d
Catch http exception on server start
edcfa55
Merge branch 'master' of https://github.com/martin-doyle/mosca
64391bb
Change server error unit test
9005cac
Change server error unit test, add check if err is null
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,77 @@ | ||
var steed = require("steed"); | ||
var steed = require('steed'); | ||
var assert = chai.assert; | ||
|
||
var moscaSettings = function() { | ||
return { | ||
port: 1883 | ||
}; | ||
var moscaSettings = function () { | ||
return { | ||
port: 1883, | ||
http: { | ||
port: 8000 | ||
} | ||
}; | ||
}; | ||
|
||
describe("mosca.Server.error", function() { | ||
var instance; | ||
var secondInstance; | ||
var settings; | ||
var moscaSettings2 = function () { | ||
return { | ||
port: 1884, | ||
http: { | ||
port: 8000 | ||
} | ||
}; | ||
}; | ||
|
||
beforeEach(function(done) { | ||
settings = moscaSettings(); | ||
settings.publishNewClient = false; | ||
settings.publishClientDisconnect = false; | ||
instance = new mosca.Server(settings, done); | ||
this.instance = instance; | ||
this.settings = settings; | ||
secondInstance = null; | ||
|
||
}); | ||
describe('mosca.Server.error', function () { | ||
var instance; | ||
var secondInstance; | ||
|
||
afterEach(function(done) { | ||
var instances = [this.instance]; | ||
beforeEach(function (done) { | ||
instance = null; | ||
secondInstance = null; | ||
done(); | ||
}); | ||
|
||
if (secondInstance) { | ||
instances.push(secondInstance); | ||
} | ||
afterEach(function (done) { | ||
this.instance = instance; | ||
var instances = [this.instance]; | ||
|
||
steed.each(instances, function(instance, cb) { | ||
instance.close(cb); | ||
}, function() { | ||
setImmediate(done); | ||
}); | ||
if (secondInstance) { | ||
instances.push(secondInstance); | ||
} | ||
|
||
steed.each(instances, function (instance, cb) { | ||
instance.close(cb); | ||
}, function () { | ||
setImmediate(done); | ||
}); | ||
}); | ||
it('should get MQTT port Error: listen EADDRINUSE', function (done) { | ||
this.timeout(10000); // have to wait for the inject with delay of two seconds | ||
instance = new mosca.Server(moscaSettings(), function (err, server) { | ||
assert.ifError(err); | ||
expect(server === instance).to.be.true; | ||
}); | ||
secondInstance = new mosca.Server(moscaSettings(), function (err, server) { | ||
assert.ifError(err); | ||
expect(server === secondInstance).to.be.true; | ||
}); | ||
secondInstance.on('error', function (err) { | ||
expect(err.toString().substr(0, 24)).to.be.equal('Error: listen EADDRINUSE'); | ||
done(); | ||
}); | ||
}); | ||
it('should get HTTP port Error: listen EADDRINUSE', function (done) { | ||
this.timeout(10000); // have to wait for the inject with delay of two seconds | ||
instance = new mosca.Server(moscaSettings(), function (err, server) { | ||
assert.ifError(err); | ||
expect(server === instance).to.be.true; | ||
}); | ||
secondInstance = new mosca.Server(moscaSettings2(), function (err, server) { | ||
assert.ifError(err); | ||
expect(server === secondInstance).to.be.true; | ||
}); | ||
it("should get Error: listen EADDRINUSE :::1883", function(done) { | ||
secondInstance = new mosca.Server(moscaSettings(), function(err, server) { | ||
expect(server === secondInstance).to.be.true; | ||
}); | ||
secondInstance.on('error', function(err) { | ||
expect(err.toString()).to.be.equal("Error: listen EADDRINUSE :::1883"); | ||
done(); | ||
}); | ||
secondInstance.on('error', function (err) { | ||
expect(err.toString().substr(0, 24)).to.be.equal('Error: listen EADDRINUSE'); | ||
done(); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can you please add an assertion that checks that
err
is null or undefined? Also in all other cases.