test: add bitcoind test for early shutdown while connecting

This commit is contained in:
Braydon Fuller 2016-05-24 16:22:41 -04:00
parent 52cf300858
commit 0cb795d980
2 changed files with 27 additions and 1 deletions

View File

@ -886,10 +886,12 @@ Bitcoin.prototype._spawnChildProcess = function(callback) {
Bitcoin.prototype._connectProcess = function(config, callback) {
var self = this;
var node = {};
var exitShutdown = false;
async.retry({times: 60, interval: self.startRetryInterval}, function(done) {
if (self.node.stopping) {
return done(new Error('Stopping while trying to connect to bitcoind.'));
exitShutdown = true;
return done();
}
node.client = new BitcoinRPC({
@ -906,6 +908,9 @@ Bitcoin.prototype._connectProcess = function(config, callback) {
if (err) {
return callback(err);
}
if (exitShutdown) {
return callback(new Error('Stopping while trying to connect to bitcoind.'));
}
self._initZmqSubSocket(node, config.zmqpubrawtx);
self._subscribeZmqEvents(node);

View File

@ -1738,6 +1738,27 @@ describe('Bitcoin Service', function() {
});
describe('#_connectProcess', function() {
it('will give error if connecting while shutting down', function(done) {
var config = {
node: {
network: bitcore.Networks.testnet
},
spawn: {
datadir: 'testdir',
exec: 'testpath'
}
};
var bitcoind = new BitcoinService(config);
bitcoind.node.stopping = true;
bitcoind.startRetryInterval = 100;
bitcoind._loadTipFromNode = sinon.stub();
bitcoind._connectProcess({}, function(err) {
err.should.be.instanceof(Error);
err.message.should.match(/Stopping while trying to connect/);
bitcoind._loadTipFromNode.callCount.should.equal(0);
done();
});
});
it('will give error from loadTipFromNode after 60 retries', function(done) {
var bitcoind = new BitcoinService(baseConfig);
bitcoind._loadTipFromNode = sinon.stub().callsArgWith(1, new Error('test'));