2019-11-01 18:30:06 +00:00
|
|
|
var client = require('../lib/dist');
|
2016-10-15 22:41:25 +00:00
|
|
|
var GossipSeed = require('../src/gossipSeed');
|
2016-03-11 23:55:27 +00:00
|
|
|
|
2016-03-14 01:38:42 +00:00
|
|
|
var testBase = require('./common/base_test');
|
2016-03-11 23:55:27 +00:00
|
|
|
|
2018-04-12 16:42:49 +00:00
|
|
|
var withSsl = !!process.env.NODE_ESC_WITH_SSL;
|
2020-09-16 15:23:46 +00:00
|
|
|
const evenstStoreType = process.env.EVENTSTORE_CONNECTION_TYPE;
|
2018-04-12 16:42:49 +00:00
|
|
|
|
2020-09-16 15:23:46 +00:00
|
|
|
module.exports = {}
|
|
|
|
|
|
|
|
switch(evenstStoreType){
|
|
|
|
case 'gossip':
|
|
|
|
module.exports['Connect to Cluster using gossip seeds'] = function (test) {
|
|
|
|
test.expect(1);
|
|
|
|
var gossipSeeds = [
|
|
|
|
new GossipSeed({host: process.env.EVENTSTORE_HOST_1 || '192.168.33.10', port: 2113}),
|
|
|
|
new GossipSeed({host: process.env.EVENTSTORE_HOST_2 || '192.168.33.11', port: 2113}),
|
|
|
|
new GossipSeed({host: process.env.EVENTSTORE_HOST_3 || '192.168.33.12', port: 2113})
|
|
|
|
];
|
|
|
|
var conn = client.EventStoreConnection.create(testBase.settings(), gossipSeeds);
|
|
|
|
conn.connect()
|
|
|
|
.catch(function(err) {
|
|
|
|
test.done(err);
|
|
|
|
});
|
|
|
|
conn.on('connected', function(endPoint){
|
|
|
|
test.ok(endPoint, 'no endpoint');
|
|
|
|
done();
|
2018-04-12 16:42:49 +00:00
|
|
|
});
|
2020-09-16 15:23:46 +00:00
|
|
|
conn.on('error', done);
|
2023-01-30 16:48:29 +00:00
|
|
|
|
2020-09-16 15:23:46 +00:00
|
|
|
function done(err) {
|
|
|
|
conn.close();
|
|
|
|
if (err) return test.done(err);
|
|
|
|
test.done();
|
|
|
|
}
|
|
|
|
};
|
2016-03-11 23:55:27 +00:00
|
|
|
|
2020-09-16 15:23:46 +00:00
|
|
|
module.exports['Connect To Cluster with bad gossip seeds'] = function (test) {
|
|
|
|
test.expect(3);
|
|
|
|
var gossipSeeds = [
|
|
|
|
new GossipSeed({host: '1.2.3.4', port: 1113}),
|
|
|
|
new GossipSeed({host: '2.3.4.5', port: 2113}),
|
|
|
|
new GossipSeed({host: '3.4.5.6', port: 3113})
|
2023-01-30 16:48:29 +00:00
|
|
|
];
|
2020-09-16 15:23:46 +00:00
|
|
|
var conn = client.EventStoreConnection.create(testBase.settings({maxDiscoverAttempts: 1}), gossipSeeds);
|
|
|
|
conn.connect()
|
|
|
|
.catch(function (err) {
|
|
|
|
test.ok(err.message.indexOf('Couldn\'t resolve target end point') === 0, 'Wrong expected reason.');
|
|
|
|
});
|
|
|
|
conn.on('connected', function () {
|
|
|
|
test.ok(false, 'Should not be able to connect.');
|
2018-04-12 16:42:49 +00:00
|
|
|
});
|
2020-09-16 15:23:46 +00:00
|
|
|
conn.on('error', function (err) {
|
|
|
|
test.ok(err.message.indexOf('Failed to discover candidate in 1 attempts') === 0, 'Wrong expected reason.');
|
2016-10-15 22:41:25 +00:00
|
|
|
});
|
2020-09-16 15:23:46 +00:00
|
|
|
conn.on('closed', function (reason) {
|
|
|
|
test.ok(reason.indexOf('Failed to resolve TCP end point to which to connect') === 0, 'Wrong expected reason.');
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 'dns':
|
|
|
|
module.exports['Connect to Cluster using dns discover'] = function (test) {
|
|
|
|
test.expect(1);
|
2023-01-30 16:48:29 +00:00
|
|
|
var clusterDns = 'discover://' + process.env.EVENTSTORE_HOST + ':2113';
|
2020-09-16 15:23:46 +00:00
|
|
|
var conn = client.EventStoreConnection.create(testBase.settings(), clusterDns);
|
|
|
|
conn.connect()
|
|
|
|
.catch(function(err) {
|
|
|
|
test.done(err);
|
|
|
|
});
|
|
|
|
conn.on('connected', function(endPoint){
|
|
|
|
test.ok(endPoint, 'no endpoint');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
conn.on('error', done);
|
2023-01-30 16:48:29 +00:00
|
|
|
|
2020-09-16 15:23:46 +00:00
|
|
|
function done(err) {
|
|
|
|
conn.close();
|
|
|
|
if (err) return test.done(err);
|
|
|
|
test.done();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports['Connect To Cluster with bad dns discover'] = function (test) {
|
|
|
|
test.expect(3);
|
2023-01-30 16:48:29 +00:00
|
|
|
var clusterDns = 'discover://abc.def.com:2113';
|
2020-09-16 15:23:46 +00:00
|
|
|
var conn = client.EventStoreConnection.create(testBase.settings({maxDiscoverAttempts: 1}), clusterDns);
|
|
|
|
conn.connect()
|
|
|
|
.catch(function (err) {
|
|
|
|
test.ok(err.message.indexOf('Couldn\'t resolve target end point') === 0, 'Wrong expected reason.');
|
|
|
|
});
|
|
|
|
conn.on('connected', function () {
|
|
|
|
test.ok(false, 'Should not be able to connect.');
|
2023-01-30 16:48:29 +00:00
|
|
|
conn.close();
|
2020-09-16 15:23:46 +00:00
|
|
|
});
|
|
|
|
conn.on('error', function (err) {
|
|
|
|
test.ok(err.message.indexOf('Failed to discover candidate in 1 attempts') === 0, 'Wrong expected reason.');
|
|
|
|
});
|
|
|
|
conn.on('closed', function (reason) {
|
|
|
|
test.ok(reason.indexOf('Failed to resolve TCP end point to which to connect') === 0, 'Wrong expected reason.');
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 'tcp':
|
|
|
|
default:
|
|
|
|
module.exports['Connect To Endpoint Happy Path'] = function (test) {
|
|
|
|
test.expect(1);
|
|
|
|
var tcpEndpoint = {host: process.env.EVENTSTORE_HOST || 'localhost', port: 1113};
|
|
|
|
var conn = client.EventStoreConnection.create(testBase.settings(), tcpEndpoint);
|
|
|
|
conn.connect()
|
|
|
|
.catch(function (err) {
|
|
|
|
test.done(err);
|
|
|
|
});
|
|
|
|
conn.on('connected', function (endPoint) {
|
|
|
|
test.areEqual('connected endPoint', endPoint, tcpEndpoint);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
conn.on('error', done);
|
2023-01-30 16:48:29 +00:00
|
|
|
|
2020-09-16 15:23:46 +00:00
|
|
|
function done(err) {
|
|
|
|
conn.close();
|
|
|
|
if (err) return test.done(err);
|
|
|
|
test.done();
|
|
|
|
}
|
|
|
|
};
|
2016-10-15 22:41:25 +00:00
|
|
|
|
2020-09-16 15:23:46 +00:00
|
|
|
module.exports['Connect To Endpoint That Doesn\'t Exist'] = function (test) {
|
|
|
|
test.expect(1);
|
|
|
|
var tcpEndpoint = {host: process.env.EVENTSTORE_HOST || 'localhost', port: 11112};
|
|
|
|
var conn = client.EventStoreConnection.create(testBase.settings({maxReconnections: 1}), tcpEndpoint);
|
|
|
|
conn.connect()
|
|
|
|
.catch(function (err) {
|
|
|
|
test.done(err);
|
|
|
|
});
|
|
|
|
conn.on('connected', function () {
|
|
|
|
test.ok(false, 'Should not be able to connect.');
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
conn.on('error', function (err) {
|
|
|
|
test.done(err);
|
|
|
|
});
|
|
|
|
conn.on('closed', function (reason) {
|
|
|
|
test.ok(reason.indexOf('Reconnection limit reached') === 0, 'Wrong expected reason.');
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
2023-01-30 16:48:29 +00:00
|
|
|
|
2020-09-16 15:23:46 +00:00
|
|
|
module.exports['Create a connection with tcp://host:port string'] = function (test) {
|
|
|
|
var conn = client.createConnection({}, `tcp://${process.env.EVENTSTORE_HOST || 'localhost'}:1113`);
|
2016-10-15 22:41:25 +00:00
|
|
|
conn.close();
|
|
|
|
test.done();
|
2020-09-16 15:23:46 +00:00
|
|
|
};
|
|
|
|
}
|
2018-04-12 16:42:49 +00:00
|
|
|
|
|
|
|
if (withSsl) {
|
|
|
|
module.exports['Connect to secure tcp endpoint'] = function(test) {
|
2018-03-11 22:25:44 +00:00
|
|
|
var conn = client.createConnection({
|
|
|
|
useSslConnection: true,
|
2020-09-16 15:23:46 +00:00
|
|
|
targetHost: process.env.EVENTSTORE_HOST || 'localhost',
|
2018-03-11 22:25:44 +00:00
|
|
|
validateServer: false
|
2020-09-16 15:23:46 +00:00
|
|
|
}, `tcp://${process.env.EVENTSTORE_HOST || 'localhost'}:1115`);
|
2018-03-11 22:25:44 +00:00
|
|
|
conn.on('error', function (err) {
|
|
|
|
test.done(err);
|
|
|
|
});
|
|
|
|
conn.connect()
|
|
|
|
.catch(function (err) {
|
|
|
|
test.done(err);
|
|
|
|
});
|
|
|
|
conn.on('connected', function () {
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
}
|
2018-04-12 16:42:49 +00:00
|
|
|
}
|
2016-03-14 01:38:42 +00:00
|
|
|
|
2019-11-01 18:30:06 +00:00
|
|
|
testBase.init(module.exports, false);
|