2016-03-11 23:55:27 +00:00
|
|
|
var client = require('../src/client.js');
|
|
|
|
|
2016-03-14 01:38:42 +00:00
|
|
|
var testBase = require('./common/base_test');
|
2016-03-11 23:55:27 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
'Connect To Endpoint Happy Path': function(test) {
|
|
|
|
var tcpEndpoint = {hostname: 'localhost', port: 1113};
|
2016-03-14 01:38:42 +00:00
|
|
|
var conn = client.EventStoreConnection.create(testBase.settings(), tcpEndpoint);
|
2016-03-11 23:55:27 +00:00
|
|
|
conn.connect()
|
2016-03-14 01:38:42 +00:00
|
|
|
.catch(function(err) {
|
|
|
|
test.done(err);
|
2016-03-11 23:55:27 +00:00
|
|
|
});
|
|
|
|
conn.on('connected', function(endPoint){
|
2016-03-14 01:38:42 +00:00
|
|
|
test.areEqual("connected endPoint", endPoint, tcpEndpoint);
|
2016-03-11 23:55:27 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
conn.on('error', done);
|
|
|
|
|
2016-03-14 01:38:42 +00:00
|
|
|
function done(err) {
|
2016-03-11 23:55:27 +00:00
|
|
|
conn.close();
|
2016-03-14 01:38:42 +00:00
|
|
|
if (err) return test.done(err);
|
2016-03-11 23:55:27 +00:00
|
|
|
test.done();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'Connect To Endpoint That Don\'t Exist': function(test) {
|
|
|
|
var tcpEndpoint = {hostname: 'localhost', port: 1114};
|
2016-03-14 01:38:42 +00:00
|
|
|
var conn = client.EventStoreConnection.create(testBase.settings({maxReconnections:1}), tcpEndpoint);
|
2016-03-11 23:55:27 +00:00
|
|
|
conn.connect()
|
2016-03-14 01:38:42 +00:00
|
|
|
.catch(function (err) {
|
|
|
|
test.done(err);
|
2016-03-11 23:55:27 +00:00
|
|
|
});
|
|
|
|
conn.on('connected', function () {
|
2016-03-14 01:38:42 +00:00
|
|
|
test.fail("Should not be able to connect.");
|
2016-03-11 23:55:27 +00:00
|
|
|
test.done();
|
|
|
|
});
|
2016-03-14 01:38:42 +00:00
|
|
|
conn.on('error', function (err) {
|
|
|
|
test.done(err);
|
2016-03-11 23:55:27 +00:00
|
|
|
});
|
|
|
|
conn.on('closed', function(reason) {
|
|
|
|
test.ok(reason.indexOf("Reconnection limit reached") === 0, "Wrong expected reason.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2016-03-14 01:38:42 +00:00
|
|
|
|
|
|
|
testBase.init(module.exports, false);
|