diff --git a/.gitignore b/.gitignore index 6569af6..3738e01 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,6 @@ lib/ .eslintrc.json jsconfig.json docs/ + +# Vagrant +.vagrant diff --git a/README.md b/README.md index c26737a..612222f 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,10 @@ var esClient = require('eventstore-node'); var uuid = require('uuid'); var streamName = "testStream"; -var esConnection = esClient.createConnection({}, {"hostname": "localhost", "port": 1113}); +var esConnection = esClient.createConnection({}, "tcp://localhost:1113"); esConnection.connect(); esConnection.once('connected', function (tcpEndPoint) { - console.log('Connected to eventstore at ' + tcpEndPoint.hostname + ":" + tcpEndPoint.port); + console.log('Connected to eventstore at ' + tcpEndPoint.host + ":" + tcpEndPoint.port); }); var eventId = uuid.v4(); diff --git a/Vagrantfile b/Vagrantfile index 7e21b60..685a753 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -10,63 +10,78 @@ Vagrant.configure("2") do |config| # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. - # Every Vagrant development environment requires a box. You can search for - # boxes at https://atlas.hashicorp.com/search. - config.vm.box = "ubuntu/trusty64" + config.vm.define "es_cluster_1" do |es_cluster_1| + es_cluster_1.vm.box = "ubuntu/trusty64" - # Disable automatic box update checking. If you disable this, then - # boxes will only be checked for updates when the user runs - # `vagrant box outdated`. This is not recommended. - config.vm.box_check_update = false + es_cluster_1.vm.box_check_update = false - # Create a forwarded port mapping which allows access to a specific port - # within the machine from a port on the host machine. In the example below, - # accessing "localhost:8080" will access port 80 on the guest machine. - # config.vm.network "forwarded_port", guest: 80, host: 8080 + es_cluster_1.vm.network "private_network", ip: "192.168.33.10" - # Create a private network, which allows host-only access to the machine - # using a specific IP. - config.vm.network "private_network", ip: "192.168.33.10" + es_cluster_1.vm.provider "virtualbox" do |vb| + vb.memory = "512" + end - # Create a public network, which generally matched to bridged network. - # Bridged networks make the machine appear as another physical device on - # your network. - # config.vm.network "public_network" - - # Share an additional folder to the guest VM. The first argument is - # the path on the host to the actual folder. The second argument is - # the path on the guest to mount the folder. And the optional third - # argument is a set of non-required options. - # config.vm.synced_folder "../data", "/vagrant_data" - - # Provider-specific configuration so you can fine-tune various - # backing providers for Vagrant. These expose provider-specific options. - # Example for VirtualBox: - # - config.vm.provider "virtualbox" do |vb| - # # Display the VirtualBox GUI when booting the machine - # vb.gui = true - # - # Customize the amount of memory on the VM: - vb.memory = "1024" + es_cluster_1.vm.provision "shell", inline: <<-SHELL + curl -s https://packagecloud.io/install/repositories/EventStore/EventStore-OSS/script.deb.sh | sudo bash + sudo apt install EventStore-OSS + sudo echo "---" > /etc/eventstore/eventstore.conf + sudo echo "RunProjections: None" >> /etc/eventstore/eventstore.conf + sudo echo "IntIp: 192.168.33.10" >> /etc/eventstore/eventstore.conf + sudo echo "ExtIp: 192.168.33.10" >> /etc/eventstore/eventstore.conf + sudo echo "ClusterSize: 3" >> /etc/eventstore/eventstore.conf + sudo echo "DiscoverViaDns: False" >> /etc/eventstore/eventstore.conf + sudo echo "GossipSeed: ['192.168.33.11:2112','192.168.33.12:2112']" >> /etc/eventstore/eventstore.conf + sudo service eventstore start + SHELL end - # - # View the documentation for the provider you are using for more - # information on available options. - # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies - # such as FTP and Heroku are also available. See the documentation at - # https://docs.vagrantup.com/v2/push/atlas.html for more information. - # config.push.define "atlas" do |push| - # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" - # end + config.vm.define "es_cluster_2" do |es_cluster_2| + es_cluster_2.vm.box = "ubuntu/trusty64" - # Enable provisioning with a shell script. Additional provisioners such as - # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the - # documentation for more information about their specific syntax and use. - config.vm.provision "shell", inline: <<-SHELL - curl -s https://packagecloud.io/install/repositories/EventStore/EventStore-OSS/script.deb.sh | sudo bash - sudo apt install EventStore-OSS - sudo service eventstore start - SHELL + es_cluster_2.vm.box_check_update = false + + es_cluster_2.vm.network "private_network", ip: "192.168.33.11" + + es_cluster_2.vm.provider "virtualbox" do |vb| + vb.memory = "512" + end + + es_cluster_2.vm.provision "shell", inline: <<-SHELL + curl -s https://packagecloud.io/install/repositories/EventStore/EventStore-OSS/script.deb.sh | sudo bash + sudo apt install EventStore-OSS + sudo echo "---" > /etc/eventstore/eventstore.conf + sudo echo "RunProjections: None" >> /etc/eventstore/eventstore.conf + sudo echo "IntIp: 192.168.33.11" >> /etc/eventstore/eventstore.conf + sudo echo "ExtIp: 192.168.33.11" >> /etc/eventstore/eventstore.conf + sudo echo "ClusterSize: 3" >> /etc/eventstore/eventstore.conf + sudo echo "DiscoverViaDns: False" >> /etc/eventstore/eventstore.conf + sudo echo "GossipSeed: ['192.168.33.10:2112','192.168.33.12:2112']" >> /etc/eventstore/eventstore.conf + sudo service eventstore start + SHELL + end + + config.vm.define "es_cluster_3" do |es_cluster_3| + es_cluster_3.vm.box = "ubuntu/trusty64" + + es_cluster_3.vm.box_check_update = false + + es_cluster_3.vm.network "private_network", ip: "192.168.33.12" + + es_cluster_3.vm.provider "virtualbox" do |vb| + vb.memory = "512" + end + + es_cluster_3.vm.provision "shell", inline: <<-SHELL + curl -s https://packagecloud.io/install/repositories/EventStore/EventStore-OSS/script.deb.sh | sudo bash + sudo apt install EventStore-OSS + sudo echo "---" > /etc/eventstore/eventstore.conf + sudo echo "RunProjections: None" >> /etc/eventstore/eventstore.conf + sudo echo "IntIp: 192.168.33.12" >> /etc/eventstore/eventstore.conf + sudo echo "ExtIp: 192.168.33.12" >> /etc/eventstore/eventstore.conf + sudo echo "ClusterSize: 3" >> /etc/eventstore/eventstore.conf + sudo echo "DiscoverViaDns: False" >> /etc/eventstore/eventstore.conf + sudo echo "GossipSeed: ['192.168.33.10:2112','192.168.33.11:2112']" >> /etc/eventstore/eventstore.conf + sudo service eventstore start + SHELL + end end diff --git a/index.d.ts b/index.d.ts index b5e725e..5780dea 100644 --- a/index.d.ts +++ b/index.d.ts @@ -25,7 +25,7 @@ export function createEventData(eventId: string, type: string, isJson: boolean, export interface TcpEndPoint { port: number; - hostname: string; + host: string; } export class GossipSeed { diff --git a/samples/simple.js b/samples/simple.js index 6f9f8fe..5b28b8a 100644 --- a/samples/simple.js +++ b/samples/simple.js @@ -6,9 +6,9 @@ var settings = { log: new client.FileLogger('./simple-verbose.log') }; var gossipSeeds = [ - new client.GossipSeed({hostname: 'localhost', port: 1113}), - new client.GossipSeed({hostname: 'localhost', port: 2113}), - new client.GossipSeed({hostname: 'localhost', port: 3113}) + new client.GossipSeed({host: '192.168.33.10', port: 2113}), + new client.GossipSeed({host: '192.168.33.11', port: 2113}), + new client.GossipSeed({host: '192.168.33.12', port: 2113}) ]; var conn = client.createConnection(settings, gossipSeeds); conn.connect() diff --git a/samples/store-event.js b/samples/store-event.js index a648b6e..f593b12 100644 --- a/samples/store-event.js +++ b/samples/store-event.js @@ -5,7 +5,7 @@ var uuid = require('uuid'); var esConnection = esClient.createConnection({}, {"hostname": "localhost", "port": 1113}); esConnection.connect(); esConnection.once('connected', function (tcpEndPoint) { - console.log('Connected to eventstore at ' + tcpEndPoint.hostname + ":" + tcpEndPoint.port); + console.log('Connected to eventstore at ' + tcpEndPoint.host + ":" + tcpEndPoint.port); var userId = uuid.v4(); // This event could happen as a result of (e.g.) a 'CreateUser(id, username, password)' command. var userCreatedEvent = { diff --git a/samples/subscribe-all-events.js b/samples/subscribe-all-events.js index 5f6b7d7..a45ba21 100644 --- a/samples/subscribe-all-events.js +++ b/samples/subscribe-all-events.js @@ -9,7 +9,7 @@ const resolveLinkTos = false; var esConnection = esClient.createConnection({}, {"hostname": "localhost", "port": 1113}); esConnection.connect(); esConnection.once('connected', function (tcpEndPoint) { - console.log('Connected to eventstore at ' + tcpEndPoint.hostname + ":" + tcpEndPoint.port); + console.log('Connected to eventstore at ' + tcpEndPoint.host + ":" + tcpEndPoint.port); esConnection.subscribeToAll(resolveLinkTos, eventAppeared, subscriptionDropped, credentialsForAllEventsStream) .then(function(subscription) { console.log("subscription.isSubscribedToAll: " + subscription.isSubscribedToAll); diff --git a/samples/subscribe-catchup-all-events.js b/samples/subscribe-catchup-all-events.js index dac2e30..2308da1 100644 --- a/samples/subscribe-catchup-all-events.js +++ b/samples/subscribe-catchup-all-events.js @@ -9,7 +9,7 @@ const credentialsForAllEventsStream = new esClient.UserCredentials("admin", "cha var esConnection = esClient.createConnection({}, {"hostname": "localhost", "port": 1113}); esConnection.connect(); esConnection.once('connected', function (tcpEndPoint) { - console.log('Connected to eventstore at ' + tcpEndPoint.hostname + ":" + tcpEndPoint.port); + console.log('Connected to eventstore at ' + tcpEndPoint.host + ":" + tcpEndPoint.port); var subscription = esConnection.subscribeToAllFrom(null, true, eventAppeared, liveProcessingStarted, subscriptionDropped, credentialsForAllEventsStream); console.log("subscription.isSubscribedToAll: " + subscription.isSubscribedToAll); }); diff --git a/src/core/clusterDnsEndPointDiscoverer.js b/src/core/clusterDnsEndPointDiscoverer.js index 8f7ba27..beeb4fd 100644 --- a/src/core/clusterDnsEndPointDiscoverer.js +++ b/src/core/clusterDnsEndPointDiscoverer.js @@ -134,7 +134,6 @@ ClusterDnsEndPointDiscoverer.prototype._getGossipCandidatesFromDns = function () ClusterDnsEndPointDiscoverer.prototype._tryGetGossipFrom = function (endPoint) { var options = { host: endPoint.endPoint.host, - hostname: endPoint.endPoint.hostname, port: endPoint.endPoint.port, path: '/gossip?format=json' }; diff --git a/src/core/operationsManager.js b/src/core/operationsManager.js index 0c06402..675728a 100644 --- a/src/core/operationsManager.js +++ b/src/core/operationsManager.js @@ -30,17 +30,20 @@ OperationsManager.prototype.getActiveOperation = function(correlationId) { return this._activeOperations.get(correlationId); }; -OperationsManager.prototype.cleanUp = function() { - var connectionClosedError = new Error(util.format("Connection '%s' was closed.", this._connectionName)); +function cleanUpError(connName, state, operation) { + return new Error(util.format("Connection '%s' was closed. %s %s.", connName, state, operation.toString())); +} +OperationsManager.prototype.cleanUp = function() { + var self = this; this._activeOperations.forEach(function(correlationId, operation){ - operation.operation.fail(connectionClosedError); + operation.operation.fail(cleanUpError(self._connectionName, 'Active', operation)); }); this._waitingOperations.forEach(function(operation) { - operation.operation.fail(connectionClosedError); + operation.operation.fail(cleanUpError(self._connectionName, 'Waiting', operation)); }); this._retryPendingOperations.forEach(function(operation) { - operation.operation.fail(connectionClosedError); + operation.operation.fail(cleanUpError(self._connectionName, 'Pending', operation)); }); this._activeOperations.clear(); diff --git a/src/eventStoreConnection.js b/src/eventStoreConnection.js index 9c984ac..987578a 100644 --- a/src/eventStoreConnection.js +++ b/src/eventStoreConnection.js @@ -49,7 +49,7 @@ function merge(a,b) { } function createFromTcpEndpoint(settings, tcpEndpoint, connectionName) { - if (!tcpEndpoint.port || !tcpEndpoint.hostname) throw new TypeError('endPoint object must have hostname and port properties.'); + if (!tcpEndpoint.port || !tcpEndpoint.host) throw new TypeError('endPoint object must have host and port properties.'); var mergedSettings = merge(defaultConnectionSettings, settings || {}); var endpointDiscoverer = new StaticEndpointDiscoverer(tcpEndpoint, settings.useSslConnection); return new EventStoreNodeConnection(mergedSettings, null, endpointDiscoverer, connectionName || null); @@ -59,11 +59,11 @@ function createFromStringEndpoint(settings, endPoint, connectionName) { var m = endPoint.match(/^(tcp|discover):\/\/([^:]+):?(\d+)?$/); if (!m) throw new Error('endPoint string must be tcp://hostname[:port] or discover://dns[:port]'); var scheme = m[1]; - var hostname = m[2]; + var host = m[2]; var port = m[3] ? parseInt(m[3]) : 1113; if (scheme === 'tcp') { var tcpEndpoint = { - hostname: hostname, + host: host, port: port }; return createFromTcpEndpoint(settings, tcpEndpoint, connectionName); diff --git a/src/gossipSeed.js b/src/gossipSeed.js index c0b88ba..e1c9d8d 100644 --- a/src/gossipSeed.js +++ b/src/gossipSeed.js @@ -1,5 +1,5 @@ module.exports = function GossipSeed(endPoint, hostName) { - //if (typeof endPoint !== 'object' || !endPoint.hostname || !endPoint.port) throw new TypeError('endPoint must be have hostname and port properties.'); + if (typeof endPoint !== 'object' || !endPoint.host || !endPoint.port) throw new TypeError('endPoint must be have host and port properties.'); Object.defineProperties(this, { endPoint: { enumerable: true, diff --git a/src/transport/tcp/tcpConnection.js b/src/transport/tcp/tcpConnection.js index 4d576b9..82b1c95 100644 --- a/src/transport/tcp/tcpConnection.js +++ b/src/transport/tcp/tcpConnection.js @@ -136,7 +136,7 @@ TcpConnection.createConnectingConnection = function( onConnectionEstablished, onConnectionFailed, onConnectionClosed ) { var connection = new TcpConnection(log, connectionId, remoteEndPoint, onConnectionClosed); - var socket = net.connect(remoteEndPoint.port, remoteEndPoint.hostname); + var socket = net.connect(remoteEndPoint.port, remoteEndPoint.host); function onError(err) { if (onConnectionFailed) onConnectionFailed(connection, err); diff --git a/test/appendToStream_test.js b/test/appendToStream_test.js index 99b5d74..d23de74 100644 --- a/test/appendToStream_test.js +++ b/test/appendToStream_test.js @@ -3,6 +3,7 @@ var client = require('../src/client'); module.exports = { 'Append One Event To Stream Happy Path': function(test) { + test.expect(2); var event = client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'testEvent'); this.conn.appendToStream(this.testStreamName, client.expectedVersion.any, event) .then(function(result) { @@ -15,6 +16,7 @@ module.exports = { }); }, 'Append Multiple Events To Stream Happy Path': function(test) { + test.expect(2); const expectedVersion = 25; var events = []; for(var i = 0; i <= expectedVersion; i++) { @@ -34,6 +36,7 @@ module.exports = { }); }, 'Append To Stream Wrong Expected Version': function(test) { + test.expect(1); var event = client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'testEvent'); this.conn.appendToStream(this.testStreamName, 10, event) .then(function(result) { @@ -48,6 +51,7 @@ module.exports = { }); }, 'Append To Stream Deleted': function(test) { + test.expect(1); var self = this; this.conn.deleteStream(this.testStreamName, client.expectedVersion.noStream, true) .then(function() { @@ -66,6 +70,7 @@ module.exports = { }); }, 'Append To Stream Access Denied': function(test) { + test.expect(1); var self = this; var metadata = {$acl: {$w: "$admins"}}; this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.noStream, metadata) diff --git a/test/cluster/manual_test.js b/test/cluster/manual_test.js new file mode 100644 index 0000000..ee9f3a7 --- /dev/null +++ b/test/cluster/manual_test.js @@ -0,0 +1,38 @@ +var client = require('../../src/client'); +var uuid = require('uuid'); + +var settings = { + log: { + info: console.log, + error: console.log, + debug: console.log + } +}; +var gossipSeeds = [ + new client.GossipSeed({host: 'localhost', port: 1113}), + new client.GossipSeed({host: 'localhost', port: 2113}), + new client.GossipSeed({host: 'localhost', port: 3113}) +]; + +var conn = client.createConnection(settings, gossipSeeds); +console.log('Connecting...'); +conn.on('connected', function (tcpEndPoint) { + console.log('Connect to', tcpEndPoint); + setTimeout(function () { + conn.appendToStream('test-' + uuid.v4(), client.expectedVersion.noStream, [ + client.createJsonEventData(uuid.v4(), {abc: 123}, {}, 'myEvent') + ]); + }, 5000); +}); +conn.on('error', function (err) { + console.log(err.stack); +}); +conn.on('closed', function (reason) { + console.log('Connection closed:', reason); + process.exit(-1); +}); +conn.connect() + .catch(function (err) { + console.log(err.stack); + process.exit(-1); + }); diff --git a/test/common/base_test.js b/test/common/base_test.js index 3a12e5b..5ea587a 100644 --- a/test/common/base_test.js +++ b/test/common/base_test.js @@ -12,7 +12,7 @@ if (process.env.TESTS_VERBOSE_LOGGING === '1') { settings.log = new FileLogger('test-verbose.log'); } -var tcpEndPoint = {hostname: 'localhost', port: 1113}; +var tcpEndPoint = {host: '192.168.33.10', port: 1113}; function setUp(cb) { this.log = settings.log; diff --git a/test/connection_test.js b/test/connection_test.js index 23ca1cc..23ba051 100644 --- a/test/connection_test.js +++ b/test/connection_test.js @@ -5,7 +5,8 @@ var testBase = require('./common/base_test'); module.exports = { 'Connect To Endpoint Happy Path': function(test) { - var tcpEndpoint = {hostname: 'localhost', port: 1113}; + test.expect(1); + var tcpEndpoint = {host: '192.168.33.10', port: 1113}; var conn = client.EventStoreConnection.create(testBase.settings(), tcpEndpoint); conn.connect() .catch(function(err) { @@ -24,7 +25,8 @@ module.exports = { } }, 'Connect To Endpoint That Doesn\'t Exist': function(test) { - var tcpEndpoint = {hostname: 'localhost', port: 11112}; + test.expect(1); + var tcpEndpoint = {host: 'localhost', port: 11112}; var conn = client.EventStoreConnection.create(testBase.settings({maxReconnections:1}), tcpEndpoint); conn.connect() .catch(function (err) { @@ -43,16 +45,16 @@ module.exports = { }); }, 'Create a connection with tcp://host:port string': function(test) { - var conn = client.createConnection({}, 'tcp://localhost:2113'); + var conn = client.createConnection({}, 'tcp://192.168.33.10:1113'); conn.close(); test.done(); }/*, 'Connect to Cluster using gossip seeds': function (test) { test.expect(1); var gossipSeeds = [ - new GossipSeed({hostname: 'localhost', port: 1113}), - new GossipSeed({hostname: 'localhost', port: 2113}), - new GossipSeed({hostname: 'localhost', port: 3113}) + new GossipSeed({host: 'localhost', port: 1113}), + new GossipSeed({host: 'localhost', port: 2113}), + new GossipSeed({host: 'localhost', port: 3113}) ]; var conn = client.EventStoreConnection.create(testBase.settings(), gossipSeeds); conn.connect() diff --git a/test/deleteStream_test.js b/test/deleteStream_test.js index a31fc30..42746cf 100644 --- a/test/deleteStream_test.js +++ b/test/deleteStream_test.js @@ -14,6 +14,7 @@ module.exports = { .catch(cb); }, 'Test Delete Stream Soft Happy Path': function(test) { + test.expect(4); var self = this; this.conn.deleteStream(this.testStreamName, 1, false) .then(function(result) { @@ -31,6 +32,7 @@ module.exports = { }); }, 'Test Delete Stream Hard Happy Path': function(test) { + test.expect(4); var self = this; this.conn.deleteStream(this.testStreamName, 1, true) .then(function(result) { @@ -48,6 +50,7 @@ module.exports = { }); }, 'Test Delete Stream With Wrong Expected Version': function(test) { + test.expect(1); this.conn.deleteStream(this.testStreamName, 10) .then(function(result) { test.fail("Delete succeeded but should have failed."); @@ -61,6 +64,7 @@ module.exports = { }); }, 'Test Delete Stream With No Access': function(test) { + test.expect(1); var self = this; this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.any, {$acl: {$d: "$admins"}}) .then(function() { @@ -78,6 +82,7 @@ module.exports = { }); }, 'Test Delete Stream Hard When Already Deleted': function(test) { + test.expect(1); var self = this; this.conn.deleteStream(this.testStreamName, 1, true) .then(function() { diff --git a/test/persistentSubscription_test.js b/test/persistentSubscription_test.js index e1bd5cc..7e47b6f 100644 --- a/test/persistentSubscription_test.js +++ b/test/persistentSubscription_test.js @@ -22,14 +22,26 @@ module.exports = { }, //TODO: Update Persistent Subscription 'Test ConnectTo Persistent Subscription': function(test) { + test.expect(2); + var _doneCount = 0; + function done(err) { + test.ok(!err, err ? err.stack : ''); + _doneCount++; + if (_doneCount < 2) return; + test.done(); + } function eventAppeared(s, e) { s.stop(); } function subscriptionDropped(connection, reason, error) { - test.done(error); + done(error); } var subscription = this.conn.connectToPersistentSubscription(testStreamName, 'consumer-1', eventAppeared, subscriptionDropped); - this.conn.appendToStream(testStreamName, client.expectedVersion.any, [createRandomEvent()]); + this.conn.appendToStream(testStreamName, client.expectedVersion.any, [createRandomEvent()]) + .then(function () { + done(); + }) + .catch(done); }, 'Test Delete Persistent Subscription': function(test) { this.conn.deletePersistentSubscription(testStreamName, 'consumer-1', adminCredentials) diff --git a/test/readAllEventsBackward_test.js b/test/readAllEventsBackward_test.js index 5b9b0bf..ea8d935 100644 --- a/test/readAllEventsBackward_test.js +++ b/test/readAllEventsBackward_test.js @@ -37,6 +37,7 @@ module.exports = { }) }, 'Read All Events Backward Happy Path': function(test) { + test.expect(4 + maxCount); var self = this; this.conn.readAllEventsBackward(client.positions.end, maxCount, false, allCredentials) .then(function(slice) { @@ -56,6 +57,7 @@ module.exports = { }) }, 'Read All Events Backward With No Access': function(test) { + test.expect(1); this.conn.readAllEventsBackward(client.positions.end, maxCount) .then(function(slice) { test.fail("readAllEventsBackward succeeded but should have failed."); diff --git a/test/readAllEventsForward_test.js b/test/readAllEventsForward_test.js index 589021d..d97f863 100644 --- a/test/readAllEventsForward_test.js +++ b/test/readAllEventsForward_test.js @@ -37,6 +37,7 @@ module.exports = { }) }, 'Read All Events Forward Happy Path': function(test) { + test.expect(5 + maxCount); this.conn.readAllEventsForward(client.positions.start, maxCount, false, allCredentials) .then(function(slice) { test.areEqual('slice.readDirection', slice.readDirection, 'forward'); @@ -57,6 +58,7 @@ module.exports = { }) }, 'Read All Events Forward With No Access': function(test) { + test.expect(1); this.conn.readAllEventsForward(client.positions.start, maxCount) .then(function(slice) { test.fail("readAllEventsForward succeeded but should have failed."); diff --git a/test/readEvent_test.js b/test/readEvent_test.js index 7690c38..ffe5268 100644 --- a/test/readEvent_test.js +++ b/test/readEvent_test.js @@ -16,6 +16,7 @@ module.exports = { .catch(cb); }, 'Read Event Happy Path': function(test) { + test.expect(8); var self = this; this.conn.readEvent(this.testStreamName, 0) .then(function(result) { @@ -35,6 +36,7 @@ module.exports = { }) }, 'Read Event From Non-Existing Stream': function(test) { + test.expect(4); var anotherStream = 'test' + uuid.v4(); this.conn.readEvent(anotherStream, 0) .then(function(result) { @@ -49,6 +51,7 @@ module.exports = { }); }, 'Read Event From Deleted Stream': function(test) { + test.expect(4); var self = this; this.conn.deleteStream(this.testStreamName, 0, true) .then(function() { @@ -66,6 +69,7 @@ module.exports = { }); }, 'Read Event With Inexisting Version': function(test) { + test.expect(4); var self = this; return self.conn.readEvent(self.testStreamName, 1) .then(function(result) { @@ -80,6 +84,7 @@ module.exports = { }); }, 'Read Event With No Access': function(test) { + test.expect(1); var self = this; var metadata = {$acl: {$r: '$admins'}}; this.conn.setStreamMetadataRaw(self.testStreamName, client.expectedVersion.noStream, metadata) diff --git a/test/readStreamEventsBackward_test.js b/test/readStreamEventsBackward_test.js index 10abbb9..2fa632f 100644 --- a/test/readStreamEventsBackward_test.js +++ b/test/readStreamEventsBackward_test.js @@ -16,6 +16,7 @@ module.exports = { .catch(cb); }, 'Read Stream Events Backward Happy Path': function(test) { + test.expect(7 + (streamSize * 6)); var self = this; this.conn.readStreamEventsBackward(this.testStreamName, streamSize-1, streamSize) .then(function(slice) { @@ -38,6 +39,7 @@ module.exports = { }) }, 'Read Stream Events Backward With Non-Existing Stream': function(test) { + test.expect(4); var anotherStream = 'test' + uuid.v4(); this.conn.readStreamEventsBackward(anotherStream, streamSize-1, streamSize) .then(function(slice) { @@ -52,6 +54,7 @@ module.exports = { }); }, 'Read Stream Events Backward With Deleted Stream': function(test) { + test.expect(4); var self = this; this.conn.deleteStream(this.testStreamName, streamSize-1, true) .then(function() { @@ -69,6 +72,7 @@ module.exports = { }); }, 'Read Stream Events Backward With Inexisting Version': function(test) { + test.expect(4); var self = this; return self.conn.readStreamEventsBackward(self.testStreamName, streamSize * 2, streamSize) .then(function(slice) { @@ -83,6 +87,7 @@ module.exports = { }); }, 'Read Stream Events Backward With No Access': function(test) { + test.expect(1); var self = this; var metadata = {$acl: {$r: '$admins'}}; this.conn.setStreamMetadataRaw(self.testStreamName, client.expectedVersion.noStream, metadata) diff --git a/test/readStreamEventsForward_test.js b/test/readStreamEventsForward_test.js index 8fbb6ba..9fe7ec9 100644 --- a/test/readStreamEventsForward_test.js +++ b/test/readStreamEventsForward_test.js @@ -16,6 +16,7 @@ module.exports = { .catch(cb); }, 'Read Stream Events Forward Happy Path': function(test) { + test.expect(7 + (streamSize * 6)); var self = this; this.conn.readStreamEventsForward(this.testStreamName, 0, streamSize) .then(function(slice) { @@ -37,6 +38,7 @@ module.exports = { }) }, 'Read Stream Events Forward With Non-Existing Stream': function(test) { + test.expect(4); var anotherStream = 'test' + uuid.v4(); this.conn.readStreamEventsForward(anotherStream, 0, streamSize) .then(function(slice) { @@ -51,6 +53,7 @@ module.exports = { }); }, 'Read Stream Events Forward With Deleted Stream': function(test) { + test.expect(4); var self = this; this.conn.deleteStream(this.testStreamName, streamSize-1, true) .then(function() { @@ -68,6 +71,7 @@ module.exports = { }); }, 'Read Stream Events Forward With Inexisting Version': function(test) { + test.expect(4); var self = this; return self.conn.readStreamEventsForward(self.testStreamName, streamSize * 2, streamSize) .then(function(slice) { @@ -82,6 +86,7 @@ module.exports = { }); }, 'Read Stream Events Forward With No Access': function(test) { + test.expect(1); var self = this; var metadata = {$acl: {$r: '$admins'}}; this.conn.setStreamMetadataRaw(self.testStreamName, client.expectedVersion.noStream, metadata) diff --git a/test/subscribeToAllFrom_test.js b/test/subscribeToAllFrom_test.js index 9f2f7af..0c1768a 100644 --- a/test/subscribeToAllFrom_test.js +++ b/test/subscribeToAllFrom_test.js @@ -9,10 +9,18 @@ function createRandomEvent() { module.exports = { 'Test Subscribe to All From': function(test) { + test.expect(4); var self = this; var liveProcessing = false; var catchUpEvents = []; var liveEvents = []; + var _doneCount = 0; + function done(err) { + test.ok(!err, err ? err.stack : ''); + _doneCount++; + if (_doneCount < 2) return; + test.done(); + } function eventAppeared(s, e) { if (liveProcessing) { liveEvents.push(e); @@ -24,12 +32,16 @@ module.exports = { function liveProcessingStarted() { liveProcessing = true; var events = [createRandomEvent()]; - self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, events); + self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, events) + .then(function () { + done(); + }) + .catch(done); } function subscriptionDropped(connection, reason, error) { test.ok(liveEvents.length === 1, "Expecting 1 live event, got " + liveEvents.length); test.ok(catchUpEvents.length > 1, "Expecting at least 1 catchUp event, got " + catchUpEvents.length); - test.done(error); + done(error); } var subscription = this.conn.subscribeToAllFrom(null, false, eventAppeared, liveProcessingStarted, subscriptionDropped, allCredentials); } diff --git a/test/subscribeToAll_test.js b/test/subscribeToAll_test.js index 82a5d7f..f753123 100644 --- a/test/subscribeToAll_test.js +++ b/test/subscribeToAll_test.js @@ -6,6 +6,15 @@ module.exports = { 'Test Subscribe To All Happy Path': function(test) { const resolveLinkTos = false; const numberOfPublishedEvents = 5; + test.expect(numberOfPublishedEvents + 4); + + var _doneCount = 0; + function done(err) { + test.ok(!err, err ? err.stack : ''); + if (++_doneCount < 2) return; + test.done(); + } + var publishedEvents = []; for(var i=0;i= 1, "Expecting at least 1 catchUp event, got " + catchUpEvents.length); - test.done(error); + done(error); } var events = [createRandomEvent()]; @@ -40,7 +53,8 @@ module.exports = { test.areEqual("subscription.isSubscribedToAll", subscription.isSubscribedToAll, false); test.areEqual("subscription.readBatchSize", subscription.readBatchSize, 500); test.areEqual("subscription.maxPushQueueSize", subscription.maxPushQueueSize, 10000); - }); + }) + .catch(test.done); } }; diff --git a/test/subscribeToStream_test.js b/test/subscribeToStream_test.js index aa50dfd..48d917d 100644 --- a/test/subscribeToStream_test.js +++ b/test/subscribeToStream_test.js @@ -5,10 +5,18 @@ module.exports = { 'Test Subscribe To Stream Happy Path': function(test) { const resolveLinkTos = false; const numberOfPublishedEvents = 5; + test.expect(numberOfPublishedEvents + 6); var publishedEvents = []; for(var i=0;i