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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #731 from martin-doyle/master
Catch exception on server start
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var steed = require("steed"); | ||
|
||
var moscaSettings = function() { | ||
return { | ||
port: 1883 | ||
}; | ||
}; | ||
|
||
describe("mosca.Server.error", function() { | ||
var instance; | ||
var secondInstance; | ||
var settings; | ||
|
||
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; | ||
|
||
}); | ||
|
||
afterEach(function(done) { | ||
var instances = [this.instance]; | ||
|
||
if (secondInstance) { | ||
instances.push(secondInstance); | ||
} | ||
|
||
steed.each(instances, function(instance, cb) { | ||
instance.close(cb); | ||
}, function() { | ||
setImmediate(done); | ||
}); | ||
}); | ||
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(); | ||
}); | ||
}); | ||
}); |