From 65e09ef281130a6b6112023c52202952af5996c1 Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Wed, 9 Sep 2015 11:08:55 -0400 Subject: [PATCH 1/4] Added integration for the bus - Added a new file that exercises the subscribe/unsubscribe/close methods with a test service - Removed a duplicate call to inherit --- integration/regtest-bus.js | 74 ++++++++++++++++++++++++++++++++++++++ lib/node.js | 2 -- 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 integration/regtest-bus.js diff --git a/integration/regtest-bus.js b/integration/regtest-bus.js new file mode 100644 index 00000000..f79f04fa --- /dev/null +++ b/integration/regtest-bus.js @@ -0,0 +1,74 @@ +'use strict'; + +var Bus = require('../lib/bus'); +var util = require('util'); +var BaseService = require('../lib/service'); + +function TestService() { + this.subscriptions = {}; + this.subscriptions['test/test'] = {}; +} +util.inherits(TestService, BaseService); + +TestService.prototype.subscribe = function(name, emitter) { + emitter.emit('Subscribe'); +}; + +TestService.prototype.unsubscribe = function(name, emitter) { + emitter.emit('Unsubscribe'); +}; + +TestService.prototype.getPublishEvents = function() { + return [ + { + name: 'test/test', + scope: this, + subscribe: this.subscribe.bind(this, 'test/test'), + unsubscribe: this.unsubscribe.bind(this, 'test/test') + } + ]; +} + +describe('Bus Functionality', function() { + var params; + before(function() { + params = { + node : { + services : [ + new TestService() + ] + } + } + }); + + after(function(done) { + done(); + }); + + it('#subscribe', function(done) { + var bus = new Bus(params); + bus.on('Subscribe', function() { + done(); + }); + bus.subscribe('test/test'); + }); + + it('#unsubscribe', function(done) { + var bus = new Bus(params); + bus.on('Unsubscribe', function() { + done(); + }); + bus.subscribe('test/test'); + bus.unsubscribe('test/test'); + }); + + it('#close', function(done) { + var bus = new Bus(params); + bus.on('Unsubscribe', function() { + done(); + }); + bus.close(); + }); + +}); + diff --git a/lib/node.js b/lib/node.js index 908f0978..3061610c 100644 --- a/lib/node.js +++ b/lib/node.js @@ -41,8 +41,6 @@ function Node(config) { util.inherits(Node, EventEmitter); -util.inherits(Node, EventEmitter); - Node.prototype._setNetwork = function(config) { if (config.network === 'testnet') { this.network = Networks.get('testnet'); From 55a3baa1aa5c472bee55ac37e12b75ca8380f419 Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Wed, 9 Sep 2015 12:25:08 -0400 Subject: [PATCH 2/4] Renamed the bus integration tests and moved it to the test directory. --- integration/regtest-bus.js => test/bus.integration.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename integration/regtest-bus.js => test/bus.integration.js (100%) diff --git a/integration/regtest-bus.js b/test/bus.integration.js similarity index 100% rename from integration/regtest-bus.js rename to test/bus.integration.js From 875c35de2ae83186cae6bda11814b2cf86b93b15 Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Thu, 10 Sep 2015 13:18:39 -0400 Subject: [PATCH 3/4] Added a full stack integration-style regtest for the bus - The test exercises subscribe and calls unsubscribe. --- integration/regtest-node.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/integration/regtest-node.js b/integration/regtest-node.js index dff7a4df..932b1483 100644 --- a/integration/regtest-node.js +++ b/integration/regtest-node.js @@ -219,4 +219,23 @@ describe('Node Functionality', function() { node.services.bitcoind.isMainChain(invalidatedBlockHash).should.equal(false); setImmediate(done); }); + + describe('Bus Functionality', function() { + it('subscribes and unsubscribes to an event on the bus', function(done) { + var bus = node.openBus(); + var block; + bus.subscribe('db/block'); + bus.on('block', function(data) { + bus.unsubscribe('db/block'); + data.should.be.equal(block); + done(); + }); + client.generate(1, function(err, response) { + if (err) { + throw err; + } + block = response.result[0]; + }); + }); + }); }); From cfcb024017849a47ba9f4adccf19c0102a8be31d Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Thu, 10 Sep 2015 14:09:56 -0400 Subject: [PATCH 4/4] Removed the old bus integration tests in favor of the one in regtest-node.js --- test/bus.integration.js | 74 ----------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 test/bus.integration.js diff --git a/test/bus.integration.js b/test/bus.integration.js deleted file mode 100644 index f79f04fa..00000000 --- a/test/bus.integration.js +++ /dev/null @@ -1,74 +0,0 @@ -'use strict'; - -var Bus = require('../lib/bus'); -var util = require('util'); -var BaseService = require('../lib/service'); - -function TestService() { - this.subscriptions = {}; - this.subscriptions['test/test'] = {}; -} -util.inherits(TestService, BaseService); - -TestService.prototype.subscribe = function(name, emitter) { - emitter.emit('Subscribe'); -}; - -TestService.prototype.unsubscribe = function(name, emitter) { - emitter.emit('Unsubscribe'); -}; - -TestService.prototype.getPublishEvents = function() { - return [ - { - name: 'test/test', - scope: this, - subscribe: this.subscribe.bind(this, 'test/test'), - unsubscribe: this.unsubscribe.bind(this, 'test/test') - } - ]; -} - -describe('Bus Functionality', function() { - var params; - before(function() { - params = { - node : { - services : [ - new TestService() - ] - } - } - }); - - after(function(done) { - done(); - }); - - it('#subscribe', function(done) { - var bus = new Bus(params); - bus.on('Subscribe', function() { - done(); - }); - bus.subscribe('test/test'); - }); - - it('#unsubscribe', function(done) { - var bus = new Bus(params); - bus.on('Unsubscribe', function() { - done(); - }); - bus.subscribe('test/test'); - bus.unsubscribe('test/test'); - }); - - it('#close', function(done) { - var bus = new Bus(params); - bus.on('Unsubscribe', function() { - done(); - }); - bus.close(); - }); - -}); -