flocore-node/test/scaffold/start.integration.js
Braydon Fuller 60af86777f Start/Stop Improvements
- A Node will shutdown if there is an error starting a service as it would lead to cascading errors.
- `node.start()` needs to be called, and nolonger is called automatically when the instance is created.
- A service will only be added to node.services after it's started
- Stopping services that are not started will gracefully continue.
- Logging sync status of db will only apply if the service is started.
- Debug log about a service without a route will always include the service name
2015-09-08 10:17:57 -04:00

106 lines
2.7 KiB
JavaScript

'use strict';
var should = require('chai').should();
var sinon = require('sinon');
var proxyquire = require('proxyquire');
var AddressService = require('../../lib/services/address');
describe('#start', function() {
describe('will dynamically create a node from a configuration', function() {
it('require each bitcore-node service with default config', function(done) {
var node;
var TestNode = function(options) {
options.services[0].should.deep.equal({
name: 'address',
module: AddressService,
config: {}
});
};
TestNode.prototype.start = sinon.stub().callsArg(0);
TestNode.prototype.on = sinon.stub();
TestNode.prototype.chain = {
on: sinon.stub()
};
var starttest = proxyquire('../../lib/scaffold/start', {
'../node': TestNode
});
node = starttest({
path: __dirname,
config: {
services: [
'address'
],
datadir: './data'
}
});
node.should.be.instanceof(TestNode);
done();
});
it('shutdown with an error from start', function(done) {
var TestNode = proxyquire('../../lib/node', {});
TestNode.prototype.start = function(callback) {
setImmediate(function() {
callback(new Error('error'));
});
};
var starttest = proxyquire('../../lib/scaffold/start', {
'../node': TestNode
});
starttest.cleanShutdown = sinon.stub();
starttest({
path: __dirname,
config: {
services: [],
datadir: './testdir'
}
});
setImmediate(function() {
starttest.cleanShutdown.callCount.should.equal(1);
done();
});
});
it('require each bitcore-node service with explicit config', function(done) {
var node;
var TestNode = function(options) {
options.services[0].should.deep.equal({
name: 'address',
module: AddressService,
config: {
param: 'test'
}
});
};
TestNode.prototype.start = sinon.stub().callsArg(0);
TestNode.prototype.on = sinon.stub();
TestNode.prototype.chain = {
on: sinon.stub()
};
var starttest = proxyquire('../../lib/scaffold/start', {
'../node': TestNode
});
node = starttest({
path: __dirname,
config: {
services: [
'address'
],
servicesConfig: {
'address': {
param: 'test'
}
},
datadir: './data'
}
});
node.should.be.instanceof(TestNode);
done();
});
});
});